-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Test ] Verify "Sign in from other device" tests (#2033)
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
Showing
7 changed files
with
345 additions
and
15 deletions.
There are no files selected for viewing
Submodule common
updated
29 files
98 changes: 98 additions & 0 deletions
98
...tity/client/msal/automationapp/testpass/broker/dcf/AbstractSignInFromOtherDeviceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
54 changes: 54 additions & 0 deletions
54
...com/microsoft/identity/client/msal/automationapp/testpass/broker/dcf/TestCase2828864.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...com/microsoft/identity/client/msal/automationapp/testpass/broker/dcf/TestCase2828868.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
...com/microsoft/identity/client/msal/automationapp/testpass/broker/dcf/TestCase2836426.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.