Skip to content

Commit

Permalink
Do not hard code the test account username and password
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Hanik committed May 15, 2014
1 parent f8ee06d commit dadb0cf
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.cloudfoundry.identity.uaa.rest.jdbc.SimpleSearchQueryConverter;
import org.cloudfoundry.identity.uaa.test.NullSafeSystemProfileValueSource;
import org.cloudfoundry.identity.uaa.test.TestUtils;
import org.cloudfoundry.identity.uaa.test.UaaTestAccounts;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -59,6 +60,7 @@
public class UserManagedAuthzApprovalHandlerTests {

private final UserManagedAuthzApprovalHandler handler = new UserManagedAuthzApprovalHandler();
private UaaTestAccounts testAccounts = UaaTestAccounts.standard(null);

@Autowired
private DataSource dataSource;
Expand Down Expand Up @@ -97,7 +99,7 @@ public void testNoScopeApproval() {
request.setApproved(true);
// The request is approved but does not request any scopes. The user has
// also not approved any scopes. Approved.
assertTrue(handler.isApproved(request, new TestAuthentication("marissa", true)));
assertTrue(handler.isApproved(request, new TestAuthentication(testAccounts.getUserName(), true)));
}

@Test
Expand All @@ -108,7 +110,7 @@ public void testNoPreviouslyApprovedScopes() {
// The request needs user approval for scopes. The user has also not
// approved any scopes prior to this request.
// Not approved.
assertFalse(handler.isApproved(request, new TestAuthentication("marissa", true)));
assertFalse(handler.isApproved(request, new TestAuthentication(testAccounts.getUserName(), true)));
}

@Test
Expand All @@ -119,14 +121,14 @@ public void testAuthzApprovedButNoPreviouslyApprovedScopes() {
// The request needs user approval for scopes. The user has also not
// approved any scopes prior to this request.
// Not approved.
assertFalse(handler.isApproved(request, new TestAuthentication("marissa", true)));
assertFalse(handler.isApproved(request, new TestAuthentication(testAccounts.getUserName(), true)));
}

@Test
public void testNoRequestedScopesButSomeApprovedScopes() {
DefaultAuthorizationRequest request = new DefaultAuthorizationRequest("foo", new HashSet<String>());
request.setApproved(false);
TestAuthentication userAuthentication = new TestAuthentication("marissa", true);
TestAuthentication userAuthentication = new TestAuthentication(testAccounts.getUserName(), true);

long theFuture = System.currentTimeMillis() + (86400 * 7 * 1000);
Date nextWeek = new Date(theFuture);
Expand All @@ -137,7 +139,7 @@ public void testNoRequestedScopesButSomeApprovedScopes() {
nextWeek, DENIED));

// The request is approved because the user has not requested any scopes
assertTrue(handler.isApproved(request, new TestAuthentication("marissa", true)));
assertTrue(handler.isApproved(request, new TestAuthentication(testAccounts.getUserName(), true)));
assertEquals(0, request.getScope().size());
}

Expand All @@ -146,7 +148,7 @@ public void testRequestedScopesDontMatchApprovalsAtAll() {
DefaultAuthorizationRequest request = new DefaultAuthorizationRequest("foo", new HashSet<String>(
Arrays.asList("openid")));
request.setApproved(false);
TestAuthentication userAuthentication = new TestAuthentication("marissa", true);
TestAuthentication userAuthentication = new TestAuthentication(testAccounts.getUserName(), true);

long theFuture = System.currentTimeMillis() + (86400 * 7 * 1000);
Date nextWeek = new Date(theFuture);
Expand All @@ -158,15 +160,15 @@ public void testRequestedScopesDontMatchApprovalsAtAll() {

// The request is not approved because the user has not yet approved the
// scopes requested
assertFalse(handler.isApproved(request, new TestAuthentication("marissa", true)));
assertFalse(handler.isApproved(request, new TestAuthentication(testAccounts.getUserName(), true)));
}

@Test
public void testOnlySomeRequestedScopeMatchesApproval() {
DefaultAuthorizationRequest request = new DefaultAuthorizationRequest("foo", new HashSet<String>(Arrays.asList(
"openid", "cloud_controller.read")));
request.setApproved(false);
TestAuthentication userAuthentication = new TestAuthentication("marissa", true);
TestAuthentication userAuthentication = new TestAuthentication(testAccounts.getUserName(), true);

long theFuture = System.currentTimeMillis() + (86400 * 7 * 1000);
Date nextWeek = new Date(theFuture);
Expand All @@ -178,15 +180,15 @@ public void testOnlySomeRequestedScopeMatchesApproval() {

// The request is not approved because the user has not yet approved all
// the scopes requested
assertFalse(handler.isApproved(request, new TestAuthentication("marissa", true)));
assertFalse(handler.isApproved(request, new TestAuthentication(testAccounts.getUserName(), true)));
}

@Test
public void testOnlySomeRequestedScopeMatchesDeniedApprovalButScopeAutoApproved() {
DefaultAuthorizationRequest request = new DefaultAuthorizationRequest("foo", new HashSet<String>(Arrays.asList(
"openid", "cloud_controller.read")));
request.setApproved(false);
TestAuthentication userAuthentication = new TestAuthentication("marissa", true);
TestAuthentication userAuthentication = new TestAuthentication(testAccounts.getUserName(), true);

long theFuture = System.currentTimeMillis() + (86400 * 7 * 1000);
Date nextWeek = new Date(theFuture);
Expand All @@ -198,7 +200,7 @@ public void testOnlySomeRequestedScopeMatchesDeniedApprovalButScopeAutoApproved(
nextWeek, DENIED));
approvalStore.addApproval(new Approval(userAuthentication.getPrincipal(), "foo", "openid", nextWeek, DENIED));

assertTrue(handler.isApproved(request, new TestAuthentication("marissa", true)));
assertTrue(handler.isApproved(request, new TestAuthentication(testAccounts.getUserName(), true)));
assertEquals(new HashSet<String>(Arrays.asList(new String[] { "cloud_controller.read", "openid" })),
request.getScope());
}
Expand All @@ -208,7 +210,7 @@ public void testRequestedScopesMatchApprovalButAdditionalScopesRequested() {
DefaultAuthorizationRequest request = new DefaultAuthorizationRequest("foo", new HashSet<String>(Arrays.asList(
"openid", "cloud_controller.read", "cloud_controller.write")));
request.setApproved(false);
TestAuthentication userAuthentication = new TestAuthentication("marissa", true);
TestAuthentication userAuthentication = new TestAuthentication(testAccounts.getUserName(), true);

long theFuture = System.currentTimeMillis() + (86400 * 7 * 1000);
Date nextWeek = new Date(theFuture);
Expand All @@ -220,15 +222,15 @@ public void testRequestedScopesMatchApprovalButAdditionalScopesRequested() {

// The request is not approved because the user has not yet approved all
// the scopes requested
assertFalse(handler.isApproved(request, new TestAuthentication("marissa", true)));
assertFalse(handler.isApproved(request, new TestAuthentication(testAccounts.getUserName(), true)));
}

@Test
public void testAllRequestedScopesMatchApproval() {
DefaultAuthorizationRequest request = new DefaultAuthorizationRequest("foo", new HashSet<String>(Arrays.asList(
"openid", "cloud_controller.read", "cloud_controller.write")));
request.setApproved(false);
TestAuthentication userAuthentication = new TestAuthentication("marissa", true);
TestAuthentication userAuthentication = new TestAuthentication(testAccounts.getUserName(), true);

long theFuture = System.currentTimeMillis() + (86400 * 7 * 1000);
Date nextWeek = new Date(theFuture);
Expand All @@ -241,7 +243,7 @@ public void testAllRequestedScopesMatchApproval() {

// The request is approved because the user has approved all the scopes
// requested
assertTrue(handler.isApproved(request, new TestAuthentication("marissa", true)));
assertTrue(handler.isApproved(request, new TestAuthentication(testAccounts.getUserName(), true)));
assertEquals(new HashSet<String>(Arrays.asList(new String[] { "openid", "cloud_controller.read",
"cloud_controller.write" })), request.getScope());
}
Expand All @@ -251,7 +253,7 @@ public void testRequestedScopesMatchApprovalButSomeDenied() {
DefaultAuthorizationRequest request = new DefaultAuthorizationRequest("foo", new HashSet<String>(Arrays.asList(
"openid", "cloud_controller.read", "cloud_controller.write")));
request.setApproved(false);
TestAuthentication userAuthentication = new TestAuthentication("marissa", true);
TestAuthentication userAuthentication = new TestAuthentication(testAccounts.getUserName(), true);

long theFuture = System.currentTimeMillis() + (86400 * 7 * 1000);
Date nextWeek = new Date(theFuture);
Expand All @@ -264,7 +266,7 @@ public void testRequestedScopesMatchApprovalButSomeDenied() {

// The request is approved because the user has acted on all requested
// scopes
assertTrue(handler.isApproved(request, new TestAuthentication("marissa", true)));
assertTrue(handler.isApproved(request, new TestAuthentication(testAccounts.getUserName(), true)));
assertEquals(new HashSet<String>(Arrays.asList(new String[] { "openid", "cloud_controller.read" })),
request.getScope());
}
Expand All @@ -274,7 +276,7 @@ public void testRequestedScopesMatchApprovalSomeDeniedButDeniedScopesAutoApprove
DefaultAuthorizationRequest request = new DefaultAuthorizationRequest("foo", new HashSet<String>(Arrays.asList(
"openid", "cloud_controller.read", "cloud_controller.write")));
request.setApproved(false);
TestAuthentication userAuthentication = new TestAuthentication("marissa", true);
TestAuthentication userAuthentication = new TestAuthentication(testAccounts.getUserName(), true);

long theFuture = System.currentTimeMillis() + (86400 * 7 * 1000);
Date nextWeek = new Date(theFuture);
Expand All @@ -294,7 +296,7 @@ public void testRequestedScopesMatchApprovalSomeDeniedButDeniedScopesAutoApprove

// The request is not approved because the user has denied some of the
// scopes requested
assertTrue(handler.isApproved(request, new TestAuthentication("marissa", true)));
assertTrue(handler.isApproved(request, new TestAuthentication(testAccounts.getUserName(), true)));
assertEquals(new HashSet<String>(Arrays.asList(new String[] { "openid", "cloud_controller.read",
"cloud_controller.write" })), request.getScope());
}
Expand All @@ -304,7 +306,7 @@ public void testSomeRequestedScopesMatchApproval() {
DefaultAuthorizationRequest request = new DefaultAuthorizationRequest("foo", new HashSet<String>(
Arrays.asList("openid")));
request.setApproved(false);
TestAuthentication userAuthentication = new TestAuthentication("marissa", true);
TestAuthentication userAuthentication = new TestAuthentication(testAccounts.getUserName(), true);

long theFuture = System.currentTimeMillis() + (86400 * 7 * 1000);
Date nextWeek = new Date(theFuture);
Expand All @@ -317,7 +319,7 @@ public void testSomeRequestedScopesMatchApproval() {

// The request is approved because the user has approved all the scopes
// requested
assertTrue(handler.isApproved(request, new TestAuthentication("marissa", true)));
assertTrue(handler.isApproved(request, new TestAuthentication(testAccounts.getUserName(), true)));
assertEquals(new HashSet<String>(Arrays.asList(new String[] { "openid" })), request.getScope());
}

Expand Down
Loading

0 comments on commit dadb0cf

Please sign in to comment.