WebApiUrlProtectedController { @PostMapping("game") public Mono<Game> createGame(@RequestBody Map<String, Object> gameRequest) { return webApiService.createGame(gameRequest); } WebApiUrlProtectedController(WebApiService webApiService); @GetMapping("games") Flux<Game> getAllGames(); @PostMapping("game") Mono<Game> createGame(@RequestBody Map<String, Object> gameRequest);  }
@Test public void createGame_BaseAuth_Admin_Ok() { List<User> users = webClient .get() .uri(USERS_URL) .headers(basicAuthHeaders(testConfig.getAdminName(), testConfig.getAdminPassword())) .retrieve() .bodyToFlux(User.class) .collect(Collectors.toList()) .block(); assertNotNull(users); assertTrue(users.size() > 3); webTestClient .post() .uri(GAME_URL) .body(BodyInserters.fromObject(createGame(users.get(0), users.get(1)))) .headers(basicAuthHeaders(testConfig.getAdminName(), testConfig.getAdminPassword())) .exchange() .expectStatus().isOk(); }
@Test public void createGame_BaseAuth_User_Forbidden() { List<User> users = webClient .get() .uri(USERS_URL) .headers(basicAuthHeaders(testConfig.getAdminName(), testConfig.getAdminPassword())) .retrieve() .bodyToFlux(User.class) .collect(Collectors.toList()) .block(); assertNotNull(users); assertTrue(users.size() > 3); webTestClient .post() .uri(GAME_URL) .body(BodyInserters.fromObject(createGame(users.get(0), users.get(1)))) .headers(basicAuthHeaders(testConfig.getUserName(), testConfig.getUserPassword())) .exchange() .expectStatus().isForbidden(); }
@Test public void createGame_TokenAuth_Admin_Ok() { List<User> users = webClient .get() .uri(USERS_URL) .headers(tokenAuthHeaders(webTestClient, testConfig.getAdminName(), testConfig.getAdminPassword())) .retrieve() .bodyToFlux(User.class) .collect(Collectors.toList()) .block(); assertNotNull(users); assertTrue(users.size() > 3); webTestClient .post() .uri(GAME_URL) .body(BodyInserters.fromObject(createGame(users.get(0), users.get(1)))) .headers(tokenAuthHeaders(webTestClient, testConfig.getAdminName(), testConfig.getAdminPassword())) .exchange() .expectStatus().isOk(); }
@Test public void createGame_TokenAuth_User_Forbidden() { List<User> users = webClient .get() .uri(USERS_URL) .headers(tokenAuthHeaders(webTestClient, testConfig.getAdminName(), testConfig.getAdminPassword())) .retrieve() .bodyToFlux(User.class) .collect(Collectors.toList()) .block(); assertNotNull(users); assertTrue(users.size() > 3); webTestClient .post() .uri(GAME_URL) .body(BodyInserters.fromObject(createGame(users.get(0), users.get(1)))) .headers(tokenAuthHeaders(webTestClient, testConfig.getUserName(), testConfig.getUserPassword())) .exchange() .expectStatus().isForbidden(); }