Search in sources :

Example 11 with AuthorizationType

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);
}
Also used : MultiAuthorizationTypeIterator(com.amplifyframework.core.model.auth.MultiAuthorizationTypeIterator) AuthorizationType(com.amplifyframework.api.aws.AuthorizationType) AuthRule(com.amplifyframework.core.model.AuthRule) Test(org.junit.Test)

Example 12 with AuthorizationType

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);
}
Also used : MultiAuthorizationTypeIterator(com.amplifyframework.core.model.auth.MultiAuthorizationTypeIterator) AuthorizationType(com.amplifyframework.api.aws.AuthorizationType) AuthRule(com.amplifyframework.core.model.AuthRule) Test(org.junit.Test)

Example 13 with AuthorizationType

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);
}
Also used : MultiAuthorizationTypeIterator(com.amplifyframework.core.model.auth.MultiAuthorizationTypeIterator) AuthorizationType(com.amplifyframework.api.aws.AuthorizationType) AuthRule(com.amplifyframework.core.model.AuthRule) Test(org.junit.Test)

Aggregations

AuthorizationType (com.amplifyframework.api.aws.AuthorizationType)13 Test (org.junit.Test)13 SubscriptionType (com.amplifyframework.api.graphql.SubscriptionType)9 AuthRule (com.amplifyframework.core.model.AuthRule)3 MultiAuthorizationTypeIterator (com.amplifyframework.core.model.auth.MultiAuthorizationTypeIterator)3 Context (android.content.Context)1 Log (android.util.Log)1 RawRes (androidx.annotation.RawRes)1 ApplicationProvider.getApplicationContext (androidx.test.core.app.ApplicationProvider.getApplicationContext)1 CognitoJWTParser (com.amazonaws.mobileconnectors.cognitoidentityprovider.util.CognitoJWTParser)1 AmplifyException (com.amplifyframework.AmplifyException)1 ApiCategory (com.amplifyframework.api.ApiCategory)1 AWSApiPlugin (com.amplifyframework.api.aws.AWSApiPlugin)1 ApiAuthProviders (com.amplifyframework.api.aws.ApiAuthProviders)1 AuthModeStrategyType (com.amplifyframework.api.aws.AuthModeStrategyType)1 DefaultCognitoUserPoolsAuthProvider (com.amplifyframework.api.aws.sigv4.DefaultCognitoUserPoolsAuthProvider)1 AuthCategory (com.amplifyframework.auth.AuthCategory)1 AWSCognitoAuthPlugin (com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin)1 AuthSignOutOptions (com.amplifyframework.auth.options.AuthSignOutOptions)1 AuthSignInResult (com.amplifyframework.auth.result.AuthSignInResult)1