From fb950e2dfa5883941620d8e9eaec6a484f2983a7 Mon Sep 17 00:00:00 2001 From: tschiman Date: Thu, 2 Feb 2017 21:18:06 -0700 Subject: [PATCH] BAEL-649 changing test content and some security changes to make all the tests work. --- .../gateway/GatewayApplicationLiveTest.java | 16 ++++++++-------- .../bootstrap/svcrating/SecurityConfig.java | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplicationLiveTest.java b/spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplicationLiveTest.java index cea431d461..aa39232bb2 100644 --- a/spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplicationLiveTest.java +++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplicationLiveTest.java @@ -14,12 +14,12 @@ public class GatewayApplicationLiveTest { TestRestTemplate testRestTemplate = new TestRestTemplate(); String testUrl = "http://localhost:8080"; - ResponseEntity response = testRestTemplate.getForEntity(testUrl + "/resource/hello/cloud", String.class); + ResponseEntity response = testRestTemplate.getForEntity(testUrl + "/book-service/books", String.class); Assert.assertEquals(HttpStatus.OK, response.getStatusCode()); - Assert.assertEquals("hello cloud", response.getBody()); + Assert.assertNotNull(response.getBody()); //try the protected resource and confirm the redirect to login - response = testRestTemplate.getForEntity(testUrl + "/resource/hello/user", String.class); + response = testRestTemplate.getForEntity(testUrl + "/book-service/books/1", String.class); Assert.assertEquals(HttpStatus.FOUND, response.getStatusCode()); Assert.assertEquals("http://localhost:8080/login", response.getHeaders().get("Location").get(0)); @@ -36,12 +36,12 @@ public class GatewayApplicationLiveTest { HttpEntity httpEntity = new HttpEntity<>(headers); //request the protected resource - response = testRestTemplate.exchange(testUrl + "/resource/hello/user", HttpMethod.GET, httpEntity, String.class); + response = testRestTemplate.exchange(testUrl + "/book-service/books/1", HttpMethod.GET, httpEntity, String.class); Assert.assertEquals(HttpStatus.OK, response.getStatusCode()); - Assert.assertEquals("hello cloud user", response.getBody()); + Assert.assertNotNull(response.getBody()); //request the admin protected resource to determine it is still protected - response = testRestTemplate.exchange(testUrl + "/resource/hello/admin", HttpMethod.GET, httpEntity, String.class); + response = testRestTemplate.exchange(testUrl + "/rating-service/ratings/all", HttpMethod.GET, httpEntity, String.class); Assert.assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode()); //login as the admin @@ -57,9 +57,9 @@ public class GatewayApplicationLiveTest { httpEntity = new HttpEntity<>(headers); //request the protected resource - response = testRestTemplate.exchange(testUrl + "/resource/hello/admin", HttpMethod.GET, httpEntity, String.class); + response = testRestTemplate.exchange(testUrl + "/rating-service/ratings/all", HttpMethod.GET, httpEntity, String.class); Assert.assertEquals(HttpStatus.OK, response.getStatusCode()); - Assert.assertEquals("hello cloud admin", response.getBody()); + Assert.assertNotNull(response.getBody()); //request the discovery resources as the admin response = testRestTemplate.exchange(testUrl + "/discovery", HttpMethod.GET, httpEntity, String.class); diff --git a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SecurityConfig.java b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SecurityConfig.java index 66b714634c..371dc810d5 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SecurityConfig.java +++ b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/SecurityConfig.java @@ -23,7 +23,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { .disable() .authorizeRequests() .antMatchers("/ratings").hasRole("USER") - .antMatchers("/ratings/all").hasAnyRole("USER", "ADMIN") + .antMatchers("/ratings/all").hasRole("ADMIN") .anyRequest().authenticated() .and() .csrf()