Skip to content

Commit fb950e2

Browse files
committed
BAEL-649 changing test content and some security changes to make all the tests work.
1 parent 2ca0929 commit fb950e2

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

‎spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplicationLiveTest.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public void testAccess() throws Exception {
1414
TestRestTemplate testRestTemplate = new TestRestTemplate();
1515
String testUrl = "http://localhost:8080";
1616

17-
ResponseEntity<String> response = testRestTemplate.getForEntity(testUrl + "/resource/hello/cloud", String.class);
17+
ResponseEntity<String> response = testRestTemplate.getForEntity(testUrl + "/book-service/books", String.class);
1818
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
19-
Assert.assertEquals("hello cloud", response.getBody());
19+
Assert.assertNotNull(response.getBody());
2020

2121
//try the protected resource and confirm the redirect to login
22-
response = testRestTemplate.getForEntity(testUrl + "/resource/hello/user", String.class);
22+
response = testRestTemplate.getForEntity(testUrl + "/book-service/books/1", String.class);
2323
Assert.assertEquals(HttpStatus.FOUND, response.getStatusCode());
2424
Assert.assertEquals("http://localhost:8080/login", response.getHeaders().get("Location").get(0));
2525

@@ -36,12 +36,12 @@ public void testAccess() throws Exception {
3636
HttpEntity<String> httpEntity = new HttpEntity<>(headers);
3737

3838
//request the protected resource
39-
response = testRestTemplate.exchange(testUrl + "/resource/hello/user", HttpMethod.GET, httpEntity, String.class);
39+
response = testRestTemplate.exchange(testUrl + "/book-service/books/1", HttpMethod.GET, httpEntity, String.class);
4040
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
41-
Assert.assertEquals("hello cloud user", response.getBody());
41+
Assert.assertNotNull(response.getBody());
4242

4343
//request the admin protected resource to determine it is still protected
44-
response = testRestTemplate.exchange(testUrl + "/resource/hello/admin", HttpMethod.GET, httpEntity, String.class);
44+
response = testRestTemplate.exchange(testUrl + "/rating-service/ratings/all", HttpMethod.GET, httpEntity, String.class);
4545
Assert.assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
4646

4747
//login as the admin
@@ -57,9 +57,9 @@ public void testAccess() throws Exception {
5757
httpEntity = new HttpEntity<>(headers);
5858

5959
//request the protected resource
60-
response = testRestTemplate.exchange(testUrl + "/resource/hello/admin", HttpMethod.GET, httpEntity, String.class);
60+
response = testRestTemplate.exchange(testUrl + "/rating-service/ratings/all", HttpMethod.GET, httpEntity, String.class);
6161
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
62-
Assert.assertEquals("hello cloud admin", response.getBody());
62+
Assert.assertNotNull(response.getBody());
6363

6464
//request the discovery resources as the admin
6565
response = testRestTemplate.exchange(testUrl + "/discovery", HttpMethod.GET, httpEntity, String.class);

‎spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SecurityConfig.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected void configure(HttpSecurity http) throws Exception {
2323
.disable()
2424
.authorizeRequests()
2525
.antMatchers("/ratings").hasRole("USER")
26-
.antMatchers("/ratings/all").hasAnyRole("USER", "ADMIN")
26+
.antMatchers("/ratings/all").hasRole("ADMIN")
2727
.anyRequest().authenticated()
2828
.and()
2929
.csrf()

0 commit comments

Comments
 (0)