33import static org .junit .Assert .assertEquals ;
44import static org .junit .Assert .assertTrue ;
55
6- import org .baeldung .Application ;
76import org .baeldung .persistence .model .Foo ;
87import org .junit .Test ;
9- import org .junit .runner .RunWith ;
10- import org .springframework .boot .test .IntegrationTest ;
11- import org .springframework .boot .test .SpringApplicationConfiguration ;
128import org .springframework .http .MediaType ;
13- import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
14- import org .springframework .test .context .web .WebAppConfiguration ;
159
1610import com .jayway .restassured .RestAssured ;
1711import com .jayway .restassured .authentication .FormAuthConfig ;
1812import com .jayway .restassured .response .Response ;
1913import com .jayway .restassured .specification .RequestSpecification ;
2014
21- @ RunWith (SpringJUnit4ClassRunner .class )
22- @ SpringApplicationConfiguration (classes = Application .class )
23- @ WebAppConfiguration
24- @ IntegrationTest ("server.port:8082" )
2515public class LiveTest {
2616
27- private final FormAuthConfig formAuthConfig = new FormAuthConfig ("http://localhost:8082/login" , "username" , "password" );
17+ private final FormAuthConfig formAuthConfig = new FormAuthConfig ("http://localhost:8082/spring-security-custom-permission/ login" , "username" , "password" );
2818
2919 @ Test
3020 public void givenUserWithReadPrivilegeAndHasPermission_whenGetFooById_thenOK () {
31- final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8082/foos/1" );
21+ final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8082/spring-security-custom-permission/ foos/1" );
3222 assertEquals (200 , response .getStatusCode ());
3323 assertTrue (response .asString ().contains ("id" ));
3424 }
3525
3626 @ Test
3727 public void givenUserWithNoWritePrivilegeAndHasPermission_whenPostFoo_thenForbidden () {
38- final Response response = givenAuth ("john" , "123" ).contentType (MediaType .APPLICATION_JSON_VALUE ).body (new Foo ("sample" )).post ("http://localhost:8082/foos" );
28+ final Response response = givenAuth ("john" , "123" ).contentType (MediaType .APPLICATION_JSON_VALUE ).body (new Foo ("sample" )).post ("http://localhost:8082/spring-security-custom-permission/ foos" );
3929 assertEquals (403 , response .getStatusCode ());
4030 }
4131
4232 @ Test
4333 public void givenUserWithWritePrivilegeAndHasPermission_whenPostFoo_thenOk () {
44- final Response response = givenAuth ("tom" , "111" ).contentType (MediaType .APPLICATION_JSON_VALUE ).body (new Foo ("sample" )).post ("http://localhost:8082/foos" );
34+ final Response response = givenAuth ("tom" , "111" ).contentType (MediaType .APPLICATION_JSON_VALUE ).body (new Foo ("sample" )).post ("http://localhost:8082/spring-security-custom-permission/ foos" );
4535 assertEquals (201 , response .getStatusCode ());
4636 assertTrue (response .asString ().contains ("id" ));
4737 }
@@ -50,22 +40,22 @@ public void givenUserWithWritePrivilegeAndHasPermission_whenPostFoo_thenOk() {
5040
5141 @ Test
5242 public void givenUserMemberInOrganization_whenGetOrganization_thenOK () {
53- final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8082/organizations/1" );
43+ final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8082/spring-security-custom-permission/ organizations/1" );
5444 assertEquals (200 , response .getStatusCode ());
5545 assertTrue (response .asString ().contains ("id" ));
5646 }
5747
5848 @ Test
5949 public void givenUserMemberNotInOrganization_whenGetOrganization_thenForbidden () {
60- final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8082/organizations/2" );
50+ final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8082/spring-security-custom-permission/ organizations/2" );
6151 assertEquals (403 , response .getStatusCode ());
6252 }
6353
6454 //
6555
6656 @ Test
6757 public void givenDisabledSecurityExpression_whenGetFooByName_thenError () {
68- final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8082/foos?name=sample" );
58+ final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8082/spring-security-custom-permission/ foos?name=sample" );
6959 assertEquals (500 , response .getStatusCode ());
7060 assertTrue (response .asString ().contains ("method hasAuthority() not allowed" ));
7161 }
0 commit comments