Skip to content

Commit

Permalink
More test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaceccanti committed Oct 28, 2021
1 parent 481a456 commit a853f94
Show file tree
Hide file tree
Showing 34 changed files with 350 additions and 677 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected OAuth2Authentication getOAuth2Authentication(ClientDetails client,

if (user.isPresent() && signatureCheckService.needsAupSignature(user.get())) {
throw new InvalidGrantException(
format("User '%s' needs to sign AUP for this organization in order to proceed.",
format("User %s needs to sign AUP for this organization in order to proceed.",
user.get().getUsername()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected OAuth2Authentication getOAuth2Authentication(final ClientDetails actor

if (account.isPresent() && signatureCheckService.needsAupSignature(account.get())) {
throw new InvalidGrantException(
format("User '%s' needs to sign AUP for this organization " + "in order to proceed.",
format("User %s needs to sign AUP for this organization " + "in order to proceed.",
account.get().getUsername()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,20 @@

import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.test.context.junit4.SpringRunner;

import com.google.common.collect.ImmutableList;
import com.nimbusds.jwt.JWT;
import com.nimbusds.jwt.JWTParser;

import it.infn.mw.iam.IamLoginService;
import it.infn.mw.iam.test.util.annotation.IamMockMvcIntegrationTest;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {IamLoginService.class})
@WebAppConfiguration
@Transactional

@RunWith(SpringRunner.class)
@IamMockMvcIntegrationTest
@TestPropertySource(properties = {"iam.access_token.include_authn_info=true"})
public class AccessTokenEnhancerTests extends EndpointsTestUtils {

Expand All @@ -59,11 +54,6 @@ public class AccessTokenEnhancerTests extends EndpointsTestUtils {
private static final String NAME = "Test User";
private static final List<String> GROUPS = ImmutableList.of("Production", "Analysis");

@Before
public void setup() throws Exception {
buildMockMvc();
}

private String getAccessTokenForUser(String scopes) throws Exception {

return new AccessTokenGetter().grantType("password").clientId(CLIENT_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,18 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.test.context.junit4.SpringRunner;

import com.nimbusds.jwt.JWT;
import com.nimbusds.jwt.JWTParser;

import it.infn.mw.iam.IamLoginService;
import it.infn.mw.iam.test.util.annotation.IamMockMvcIntegrationTest;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {IamLoginService.class})
@WebAppConfiguration
@Transactional
@RunWith(SpringRunner.class)
@IamMockMvcIntegrationTest
@TestPropertySource(properties = {"iam.access_token.include_scope=true"})
public class AccessTokenIncludeScopeTests extends EndpointsTestUtils {
private static final String CLIENT_CREDENTIALS_CLIENT_ID = "client-cred";
Expand All @@ -48,11 +42,6 @@ public class AccessTokenIncludeScopeTests extends EndpointsTestUtils {
private static final String USERNAME = "test";
private static final String PASSWORD = "password";

@Before
public void setup() throws Exception {
buildMockMvc();
}

@Test
public void testScopeIncludedInAccessTokenClientCred() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,25 @@
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.log;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.nimbusds.jwt.JWT;
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.JWTParser;

import it.infn.mw.iam.IamLoginService;
import it.infn.mw.iam.test.util.annotation.IamMockMvcIntegrationTest;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = IamLoginService.class)
@WebAppConfiguration
@Transactional

@RunWith(SpringRunner.class)
@IamMockMvcIntegrationTest
public class AudienceTests {

public static final String TEST_USERNAME = "test";
Expand All @@ -60,20 +51,12 @@ public class AudienceTests {
public static final String CLIENT_CRED_GRANT_CLIENT_ID = "client-cred";
public static final String CLIENT_CRED_GRANT_CLIENT_SECRET = "secret";

@Autowired
private WebApplicationContext context;

@Autowired
private ObjectMapper mapper;

@Autowired
private MockMvc mvc;

@Before
public void before() {
mvc =
MockMvcBuilders.webAppContextSetup(context).alwaysDo(log()).apply(springSecurity()).build();
}

@Test
public void testAudienceRequestPasswordFlow() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.util.UriComponentsBuilder;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand All @@ -43,13 +40,11 @@
import com.nimbusds.jwt.JWT;
import com.nimbusds.jwt.JWTParser;

import it.infn.mw.iam.IamLoginService;
import it.infn.mw.iam.test.TestUtils;
import it.infn.mw.iam.test.util.annotation.IamRandomPortIntegrationTest;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {IamLoginService.class})
@WebIntegrationTest(randomPort = true)
@Transactional
@RunWith(SpringRunner.class)
@IamRandomPortIntegrationTest
public class AuthorizationCodeIntegrationTests {

@Value("${local.server.port}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,34 @@

import static java.lang.String.format;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.securityContext;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.log;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;

import java.util.Date;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

import com.fasterxml.jackson.databind.ObjectMapper;

import it.infn.mw.iam.IamLoginService;
import it.infn.mw.iam.persistence.model.IamAup;
import it.infn.mw.iam.persistence.repository.IamAupRepository;
import it.infn.mw.iam.test.util.WithAnonymousUser;
import it.infn.mw.iam.test.util.annotation.IamMockMvcIntegrationTest;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = IamLoginService.class)
@WebAppConfiguration
@WithAnonymousUser
@Transactional

@RunWith(SpringRunner.class)
@IamMockMvcIntegrationTest
public class AuthorizationCodeTests {

public static final String TEST_CLIENT_ID = "client";
Expand All @@ -77,25 +66,16 @@ public class AuthorizationCodeTests {
public static final String TEST_USER_PASSWORD = "password";

@Autowired
WebApplicationContext context;

@Autowired
ObjectMapper objectMapper;
private ObjectMapper objectMapper;

@Autowired
IamAupRepository aupRepo;
private IamAupRepository aupRepo;

@Value("${iam.baseUrl}")
String iamBaseUrl;

MockMvc mvc;

@Before
public void setup() {
mvc =
MockMvcBuilders.webAppContextSetup(context).apply(springSecurity()).alwaysDo(log()).build();
}
private String iamBaseUrl;

@Autowired
private MockMvc mvc;

@Test
public void testOidcAuthorizationCodeFlowExternalHint() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,28 @@
package it.infn.mw.iam.test.oauth;

import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.log;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;

import it.infn.mw.iam.IamLoginService;
import it.infn.mw.iam.test.util.WithAnonymousUser;
import it.infn.mw.iam.test.util.annotation.IamMockMvcIntegrationTest;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = IamLoginService.class)
@WebAppConfiguration
@Transactional
@WithAnonymousUser

@RunWith(SpringRunner.class)
@IamMockMvcIntegrationTest
@TestPropertySource(properties= {"clientRegistration.allowFor=REGISTERED_USERS"})
public class ClientRegistrationAuthzTests extends ClientRegistrationTestSupport {

@Autowired
private WebApplicationContext context;

private MockMvc mvc;

@Before
public void setup() throws Exception {
mvc = MockMvcBuilders.webAppContextSetup(context)
.apply(springSecurity())
.alwaysDo(log())
.build();
}

@Test
public void testClientRegistrationRequiresAuthenticatedUser() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,36 @@

import static org.hamcrest.CoreMatchers.is;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.log;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mitre.oauth2.model.SystemScope;
import org.mitre.oauth2.repository.SystemScopeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;

import it.infn.mw.iam.IamLoginService;
import it.infn.mw.iam.test.util.annotation.IamMockMvcIntegrationTest;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = IamLoginService.class)
@WebAppConfiguration
@Transactional

@RunWith(SpringRunner.class)
@IamMockMvcIntegrationTest
@TestPropertySource(
properties = {"scope.matchers[0].name=storage.read", "scope.matchers[0].type=path",
"scope.matchers[0].prefix=storage.read", "scope.matchers[0].path=/"})
public class ClientRegistrationScopeFilteringTests extends ClientRegistrationTestSupport {

@Autowired
private WebApplicationContext context;

@Autowired
private SystemScopeRepository scopeRepo;

@Autowired
private MockMvc mvc;

@Before
public void setup() throws Exception {
mvc =
MockMvcBuilders.webAppContextSetup(context).apply(springSecurity()).alwaysDo(log()).build();
}

@Test
public void testClientRegistrationScopesAreFiltered() throws Exception {

Expand Down
Loading

0 comments on commit a853f94

Please sign in to comment.