Skip to content

Commit

Permalink
[Test ] Verify "Sign in from other device" tests (#2033)
Browse files Browse the repository at this point in the history
Adding test to execute "Sign in from other device" flow and verify if if
remote login url is shown to the user.

The flow works only in brokered auth and if
"is_remote_login_allowed=true" is passedin extra query auth parameters.

Since Sov cloud and WW have different remote login urls
There are two test cases.

Supporting PR in common:
Common PR:
AzureAD/microsoft-authentication-library-common-for-android#2308

Related PR in broker:
AzureAD/ad-accounts-for-android#2696
  • Loading branch information
mohitc1 authored Feb 13, 2024
1 parent 194c33e commit 34ea992
Show file tree
Hide file tree
Showing 7 changed files with 345 additions and 15 deletions.
2 changes: 1 addition & 1 deletion common
Submodule common updated 29 files
+5 −0 changelog.txt
+2 −1 common/src/main/java/com/microsoft/identity/common/exception/BrokerCommunicationException.kt
+4 −4 .../microsoft/identity/common/internal/broker/ipc/AccountManagerBackupIpcStrategyTargetingSpecificBrokerApp.kt
+68 −0 common/src/main/java/com/microsoft/identity/common/internal/broker/ipc/IpcStrategyWithBackup.kt
+2 −39 common/src/main/java/com/microsoft/identity/common/internal/controllers/BrokerMsalController.java
+21 −23 common/src/main/java/com/microsoft/identity/common/internal/controllers/LocalMSALController.java
+11 −1 common/src/main/java/com/microsoft/identity/common/internal/fido/WebAuthnJsonUtil.kt
+1 −3 common/src/main/java/com/microsoft/identity/common/internal/ui/browser/BrowserAuthorizationStrategy.java
+2 −2 ...n/src/main/java/com/microsoft/identity/common/internal/ui/webview/EmbeddedWebViewAuthorizationStrategy.java
+13 −2 common/src/main/java/com/microsoft/identity/common/internal/util/AccountManagerUtil.java
+84 −0 common/src/main/java/com/microsoft/identity/common/sharedwithoneauth/OneAuthSharedFunctions.kt
+2 −2 ...rosoft/identity/common/internal/broker/ipc/AccountManagerBackupIpcStrategyTargetingSpecificBrokerAppTest.kt
+157 −0 common/src/test/java/com/microsoft/identity/common/internal/broker/ipc/IpcStrategyWithBackupTests.kt
+30 −3 common/src/test/java/com/microsoft/identity/common/internal/fido/WebAuthnJsonUtilTest.kt
+6 −5 common4j/src/main/com/microsoft/identity/common/java/controllers/CommandDispatcher.java
+9 −1 common4j/src/main/com/microsoft/identity/common/java/flighting/CommonFlight.java
+14 −0 common4j/src/main/com/microsoft/identity/common/java/flighting/CommonFlightManager.java
+20 −5 common4j/src/main/com/microsoft/identity/common/java/flighting/IFlightsProvider.java
+11 −1 common4j/src/main/com/microsoft/identity/common/java/opentelemetry/AttributeName.java
+40 −0 common4j/src/main/com/microsoft/identity/common/java/opentelemetry/OTelUtility.java
+1 −3 common4j/src/main/com/microsoft/identity/common/java/providers/oauth2/OAuth2Strategy.java
+9 −0 common4j/src/test/com/microsoft/identity/common/java/flighting/MockFlightsProvider.java
+1 −1 gradle/versions.gradle
+1 −1 .../src/main/java/com/microsoft/identity/internal/testutils/strategies/MockStrategyWithMockedHttpResponse.java
+1 −2 testutils/src/main/java/com/microsoft/identity/internal/testutils/strategies/MockTestStrategy.java
+1 −1 ...java/com/microsoft/identity/internal/testutils/strategies/ResourceOwnerPasswordCredentialsTestStrategy.java
+22 −0 ...ain/java/com/microsoft/identity/client/ui/automation/interaction/microsoftsts/AadLoginComponentHandler.java
+14 −0 ...om/microsoft/identity/client/ui/automation/interaction/microsoftsts/IMicrosoftStsLoginComponentHandler.java
+20 −4 uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/sdk/IAuthSdk.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.client.msal.automationapp.testpass.broker.dcf;

import androidx.annotation.NonNull;

import com.microsoft.identity.client.Prompt;
import com.microsoft.identity.client.msal.automationapp.R;
import com.microsoft.identity.client.msal.automationapp.sdk.MsalAuthTestParams;
import com.microsoft.identity.client.msal.automationapp.sdk.MsalSdk;
import com.microsoft.identity.client.msal.automationapp.testpass.broker.AbstractMsalBrokerTest;
import com.microsoft.identity.client.ui.automation.TokenRequestTimeout;
import com.microsoft.identity.client.ui.automation.interaction.microsoftsts.AadLoginComponentHandler;
import com.microsoft.identity.labapi.utilities.client.LabQuery;
import com.microsoft.identity.labapi.utilities.constants.AzureEnvironment;
import com.microsoft.identity.labapi.utilities.constants.TempUserType;
import com.microsoft.identity.labapi.utilities.constants.UserType;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

// Brokered Auth verify "Sign In from other device" option.
abstract class AbstractSignInFromOtherDeviceTest extends AbstractMsalBrokerTest {

private final AzureEnvironment mAzureEnvironment;

public AbstractSignInFromOtherDeviceTest(@NonNull AzureEnvironment environment) {
mAzureEnvironment = environment;
}

@Override
public LabQuery getLabQuery() {
return LabQuery.builder()
.userType(UserType.CLOUD)
.azureEnvironment(mAzureEnvironment)
.build();
}

@Override
public TempUserType getTempUserType() {
return null;
}

@Override
public String[] getScopes() {
return new String[]{"User.read"};
}

@Override
public String getAuthority() {
return mApplication.getConfiguration().getDefaultAuthority().getAuthorityURL().toString();
}

protected void testSignInFromOtherDevice() throws Throwable {
final MsalSdk msalSdk = new MsalSdk();
final List<Map.Entry<String, String>> extraQP = new ArrayList<>();
extraQP.add(new AbstractMap.SimpleEntry<>("is_remote_login_allowed", Boolean.toString(true)));

final MsalAuthTestParams authTestParams = MsalAuthTestParams.builder()
.activity(mActivity)
.scopes(Arrays.asList(mScopes))
.msalConfigResourceId(getConfigFileResourceId())
.extraQueryParameters(extraQP)
.build();

msalSdk.acquireTokenInteractiveAsync(authTestParams, () ->
new AadLoginComponentHandler().handleSignInFromOtherDevice(getExpectedDeviceCodeUrl()), TokenRequestTimeout.MEDIUM);
}

abstract protected String getExpectedDeviceCodeUrl();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.client.msal.automationapp.testpass.broker.dcf;

import com.microsoft.identity.client.msal.automationapp.R;
import com.microsoft.identity.client.ui.automation.annotations.RetryOnFailure;
import com.microsoft.identity.labapi.utilities.constants.AzureEnvironment;

import org.junit.Test;

// Brokered Auth verify "Sign In from other device" option and remote login url.
// https://identitydivision.visualstudio.com/Engineering/_workitems/edit/2828864
@RetryOnFailure(retryCount = 2)
public class TestCase2828864 extends AbstractSignInFromOtherDeviceTest {

public TestCase2828864() {
super(AzureEnvironment.AZURE_CLOUD);
}

@Test
public void test_2828864() throws Throwable {
this.testSignInFromOtherDevice();
}

@Override
public int getConfigFileResourceId() {
return R.raw.msal_config_default;
}

@Override
protected String getExpectedDeviceCodeUrl() {
return "https://microsoft.com/devicelogin";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.client.msal.automationapp.testpass.broker.dcf;

import com.microsoft.identity.client.msal.automationapp.R;
import com.microsoft.identity.client.ui.automation.annotations.RetryOnFailure;
import com.microsoft.identity.labapi.utilities.constants.AzureEnvironment;

import org.junit.Test;

// Brokered Auth verify "Sign In from other device" option for Us Gov and and remote login url.
// https://identitydivision.visualstudio.com/Engineering/_workitems/edit/2828868
@RetryOnFailure(retryCount = 2)
public class TestCase2828868 extends AbstractSignInFromOtherDeviceTest {
public TestCase2828868() {
super(AzureEnvironment.AZURE_US_GOVERNMENT);
}

@Test
public void test_2828868() throws Throwable {
this.testSignInFromOtherDevice();
}

@Override
public int getConfigFileResourceId() {
return R.raw.msal_config_arlington;
}

@Override
protected String getExpectedDeviceCodeUrl() {
return "https://microsoft.com/deviceloginus";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.client.msal.automationapp.testpass.broker.dcf;

import static com.microsoft.identity.client.ui.automation.interaction.microsoftsts.AadLoginComponentHandler.SIGN_IN_FROM_OTHER_DEVICE;

import com.microsoft.identity.client.msal.automationapp.R;
import com.microsoft.identity.client.msal.automationapp.sdk.MsalAuthTestParams;
import com.microsoft.identity.client.msal.automationapp.sdk.MsalSdk;
import com.microsoft.identity.client.msal.automationapp.testpass.broker.AbstractMsalBrokerTest;
import com.microsoft.identity.client.ui.automation.TokenRequestTimeout;
import com.microsoft.identity.client.ui.automation.annotations.RetryOnFailure;
import com.microsoft.identity.client.ui.automation.interaction.microsoftsts.AadLoginComponentHandler;
import com.microsoft.identity.client.ui.automation.utils.UiAutomatorUtils;
import com.microsoft.identity.labapi.utilities.client.LabQuery;
import com.microsoft.identity.labapi.utilities.constants.AzureEnvironment;
import com.microsoft.identity.labapi.utilities.constants.TempUserType;
import com.microsoft.identity.labapi.utilities.constants.UserType;

import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;

// Brokered Auth to verify "Sign In from other device" option is not present
// if "is_remote_login_allowed=true" query parameter is not present.
// https://identitydivision.visualstudio.com/Engineering/_workitems/edit/2836426
@RetryOnFailure(retryCount = 2)
public class TestCase2836426 extends AbstractMsalBrokerTest {

@Test
public void test_2836426() throws Throwable {
final MsalSdk msalSdk = new MsalSdk();

// don't pass "is_remote_login_allowed=true" query parameter
final MsalAuthTestParams authTestParams = MsalAuthTestParams.builder()
.activity(mActivity)
.scopes(Arrays.asList(mScopes))
.msalConfigResourceId(getConfigFileResourceId())
.build();

msalSdk.acquireTokenInteractiveAsync(authTestParams, () ->
new AadLoginComponentHandler().handleSignInOptions(), TokenRequestTimeout.MEDIUM);

// ensure "Sign in from other device" option is no present.
Assert.assertFalse(UiAutomatorUtils.obtainUiObjectWithText(SIGN_IN_FROM_OTHER_DEVICE).exists());
}

@Override
public String[] getScopes() {
return new String[]{"User.read"};
}

@Override
public String getAuthority() {
return mApplication.getConfiguration().getDefaultAuthority().getAuthorityURL().toString();
}

@Override
public int getConfigFileResourceId() {
return R.raw.msal_config_default;
}

@Override
public LabQuery getLabQuery() {
return LabQuery.builder()
.userType(UserType.CLOUD)
.azureEnvironment(AzureEnvironment.AZURE_CLOUD)
.build();
}

@Override
public TempUserType getTempUserType() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.microsoft.identity.client.ui.automation.sdk.AuthTestParams;

import java.util.List;
import java.util.Map;

import lombok.Getter;
import lombok.experimental.SuperBuilder;
Expand All @@ -41,4 +42,5 @@ public class MsalAuthTestParams extends AuthTestParams {
private final int msalConfigResourceId;
private final List<String> scopes;
private final ClaimsRequest claims;
private final List<Map.Entry<String, String>> extraQueryParameters;
}
Loading

0 comments on commit 34ea992

Please sign in to comment.