Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
p3dr0rv committed Nov 30, 2023
1 parent 0228bdb commit 2058c0c
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.test.core.app.ApplicationProvider;

import com.microsoft.identity.client.claims.ClaimsRequest;
Expand All @@ -42,6 +43,7 @@
import com.microsoft.identity.common.java.constants.FidoConstants;
import com.microsoft.identity.common.java.providers.oauth2.OAuth2TokenCache;
import com.microsoft.identity.common.java.exception.ClientException;
import com.microsoft.identity.common.java.ui.PreferredAuthMethod;

import org.junit.Assert;
import org.junit.Before;
Expand All @@ -61,7 +63,7 @@
import java.util.UUID;

@RunWith(RobolectricTestRunner.class)
@Ignore("Passkey feature in development.")
//@Ignore("Passkey feature in development.")
public class CommandParametersTest {

private static final String AAD_CP1_CONFIG_FILE = "src/test/res/raw/aad_capabilities_cp1.json";
Expand Down Expand Up @@ -142,6 +144,28 @@ public void testAcquireTokenOperationWithCorrelationId() throws ClientException
Assert.assertEquals(correlationId.toString(), commandParameters.getCorrelationId());
}

@Test
public void testAcquireTokenOperationWithPreferredAuthMethod() throws ClientException {

InteractiveTokenCommandParameters commandParameters = CommandParametersAdapter.createInteractiveTokenCommandParameters(
getConfiguration(AAD_NONE_CONFIG_FILE),
getCache(),
getAcquireTokenParametersPreferredAuthMethod(PreferredAuthMethod.QR)
);
Assert.assertEquals(PreferredAuthMethod.QR, commandParameters.getPreferredAuthMethod());
}

@Test
public void testAcquireTokenOperationWithNoPreferredAuthMethod() throws ClientException {

InteractiveTokenCommandParameters commandParameters = CommandParametersAdapter.createInteractiveTokenCommandParameters(
getConfiguration(AAD_NONE_CONFIG_FILE),
getCache(),
getAcquireTokenParametersPreferredAuthMethod(null)
);
Assert.assertNull(commandParameters.getPreferredAuthMethod());
}

@Test
public void testAcquireTokenSilentOperationWithoutCorrelationId() throws ClientException {
SilentTokenCommandParameters commandParameters = CommandParametersAdapter.createSilentTokenCommandParameters(getConfiguration(AAD_CP1_CONFIG_FILE), getCache(), getAcquireTokenSilentParametersWithoutCorrelationId());
Expand Down Expand Up @@ -336,6 +360,17 @@ private AcquireTokenSilentParameters getAcquireTokenSilentParametersWithCorrelat
return parameters;
}

private AcquireTokenParameters getAcquireTokenParametersPreferredAuthMethod(final @Nullable PreferredAuthMethod preferredAuthMethod) {
final AcquireTokenParameters.Builder parametersBuilder = new AcquireTokenParameters.Builder()
.withClaims(getAccessTokenClaimsRequest("device_id", ""))
.withScopes(new ArrayList<String>(Arrays.asList("User.Read")))
.startAuthorizationFromActivity(mActivity);
if (preferredAuthMethod != null) {
parametersBuilder.withPreferredAuthMethod(preferredAuthMethod);
}
return parametersBuilder.build();
}

private AcquireTokenParameters getAcquireTokenParametersWithoutCorrelationId() {
AcquireTokenParameters parameters = new AcquireTokenParameters.Builder()
.withClaims(getAccessTokenClaimsRequest("device_id", ""))
Expand Down

0 comments on commit 2058c0c

Please sign in to comment.