use of com.amplifyframework.api.aws.AuthorizationType in project amplify-android by aws-amplify.
the class MultiAuthorizationTypeIteratorTest method testOwnerAndGroupRules.
/**
* Verify that if there are mixed owner and group rules, we return the auth types in the correct order.
* We're verifying that:
* - both owner rules are processed first (userPools and oidc) with isOwner = true.
* - both group rules are processed next (userPools and oidc) withg isOwner = false.
*
* isOwner is used in the code to determine whether a request may need the owner parameter added.
*/
@Test
public void testOwnerAndGroupRules() {
Iterator<AuthorizationType> expectedAuthTypes = Arrays.asList(AuthorizationType.AMAZON_COGNITO_USER_POOLS, AuthorizationType.OPENID_CONNECT, AuthorizationType.AMAZON_COGNITO_USER_POOLS, AuthorizationType.OPENID_CONNECT).iterator();
Iterator<Boolean> expectedIsOwnerFlags = Arrays.asList(true, true, false, false).iterator();
List<AuthRule> authRules = Arrays.asList(buildOwnerRule(null, null, null, null), buildOwnerRule(AuthStrategy.Provider.USER_POOLS, "differentOwnerField", null, CREATE_DELETE_OPERATIONS), buildOwnerRule(AuthStrategy.Provider.OIDC, "differentOwner", "myClaim", null), buildGroupRule(null, null, null, null, null), buildGroupRule(AuthStrategy.Provider.OIDC, "myGroupField", "someClaim", Collections.singletonList("group1"), null));
MultiAuthorizationTypeIterator actualAuthTypeIterator = new MultiAuthorizationTypeIterator(authRules);
assertIteratorState(expectedAuthTypes, expectedIsOwnerFlags, actualAuthTypeIterator);
}
use of com.amplifyframework.api.aws.AuthorizationType in project amplify-android by aws-amplify.
the class MultiAuthorizationTypeIteratorTest method testAllRules.
/**
* Test a schema with auth rules for each strategy is returned in the expected order.
*/
@Test
public void testAllRules() {
Iterator<AuthorizationType> expectedAuthTypes = Arrays.asList(AuthorizationType.AMAZON_COGNITO_USER_POOLS, AuthorizationType.OPENID_CONNECT, AuthorizationType.AWS_IAM, AuthorizationType.API_KEY).iterator();
Iterator<Boolean> expectedIsOwnerFlags = Arrays.asList(true, false, false, false).iterator();
List<AuthRule> authRules = Arrays.asList(buildGroupRule(AuthStrategy.Provider.OIDC, null, null, null, null), buildPrivateRule(AuthStrategy.Provider.IAM, null), buildOwnerRule(null, null, null, null), buildPublicRule(null, null));
MultiAuthorizationTypeIterator actualAuthTypeIterator = new MultiAuthorizationTypeIterator(authRules);
assertIteratorState(expectedAuthTypes, expectedIsOwnerFlags, actualAuthTypeIterator);
}
use of com.amplifyframework.api.aws.AuthorizationType in project amplify-android by aws-amplify.
the class MultiAuthorizationTypeIteratorTest method testMultiOwnerRules.
/**
* If there are multiple owner based rules (a couple using userPools and one using oidc),
* it should only return 2 auth types (one for userPools and one for oidc).
*/
@Test
public void testMultiOwnerRules() {
Iterator<AuthorizationType> expectedAuthTypes = Arrays.asList(AuthorizationType.AMAZON_COGNITO_USER_POOLS, AuthorizationType.OPENID_CONNECT).iterator();
Iterator<Boolean> expectedIsOwnerFlags = Arrays.asList(true, true).iterator();
List<AuthRule> authRules = Arrays.asList(buildOwnerRule(AuthStrategy.Provider.OIDC, "differentOwner", "myClaim", Arrays.asList(ModelOperation.CREATE, ModelOperation.DELETE)), buildOwnerRule(null, null, null, null), buildOwnerRule(AuthStrategy.Provider.USER_POOLS, "differentOwnerField", null, Arrays.asList(ModelOperation.CREATE, ModelOperation.DELETE)));
MultiAuthorizationTypeIterator actualAuthTypeIterator = new MultiAuthorizationTypeIterator(authRules);
assertIteratorState(expectedAuthTypes, expectedIsOwnerFlags, actualAuthTypeIterator);
}
Aggregations