Skip to content

Commit 5df9fce

Browse files
committed
[skip test][CognitoAuth] Add tests for no scopes cache; fix diamond operator (#879) [bump version 2.13.1]
1 parent 3176e99 commit 5df9fce

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

aws-android-sdk-cognitoauth/src/androidTest/java/com/amazonaws/mobileconnectors/cognitoauth/LocalDataManagerIntegrationTest.java

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,52 @@ public void onFailure(Exception e) {
214214
setFromString("email,profile,openid"));
215215

216216
printSharedPreferencesKeys();
217-
verifySharedPreferencesForCachedState(auth.awsKeyValueStore);
217+
verifySharedPreferencesForCachedState(auth.awsKeyValueStore, "proofKey", "email,profile,openid");
218+
} catch (Exception ex) {
219+
ex.printStackTrace();
220+
assertTrue("Error occurred" + ex, false);
221+
}
222+
}
223+
224+
@Test
225+
public void testCognitoAuthCachedStateForNoScopes() {
226+
printSharedPreferencesKeys();
227+
228+
try {
229+
Auth.Builder builder = new Auth.Builder();
230+
Auth auth = builder.setAppClientId(getPackageConfigure().getString("AppClientId"))
231+
.setAppCognitoWebDomain(getPackageConfigure().getString("WebDomain"))
232+
.setSignInRedirect(getPackageConfigure().getString("SignInRedirectURI"))
233+
.setSignOutRedirect(getPackageConfigure().getString("SignOutRedirectURI"))
234+
.setApplicationContext(InstrumentationRegistry.getTargetContext())
235+
.setAdvancedSecurityDataCollection(true)
236+
.setScopes(new HashSet<String>())
237+
.setAuthHandler(new AuthHandler() {
238+
@Override
239+
public void onSuccess(AuthUserSession session) {
240+
241+
}
242+
243+
@Override
244+
public void onSignout() {
245+
246+
}
247+
248+
@Override
249+
public void onFailure(Exception e) {
250+
251+
}
252+
})
253+
.build();
254+
assertNotNull(auth);
255+
256+
LocalDataManager.cacheState(auth.awsKeyValueStore, InstrumentationRegistry.getTargetContext(),
257+
"key",
258+
"proofKey",
259+
new HashSet<String>());
260+
261+
printSharedPreferencesKeys();
262+
verifySharedPreferencesForCachedState(auth.awsKeyValueStore, "proofKey", null);
218263
} catch (Exception ex) {
219264
ex.printStackTrace();
220265
assertTrue("Error occurred" + ex, false);
@@ -358,13 +403,13 @@ private void verifySharedPreferencesForCachedSession() {
358403
assertNotNull(sharedPreferencesForAuth.getString(lastAuthUserKey, null));
359404
}
360405

361-
private void verifySharedPreferencesForCachedState(AWSKeyValueStore awsKeyValueStore) {
406+
private void verifySharedPreferencesForCachedState(AWSKeyValueStore awsKeyValueStore, String proofKeyValue, String scopesValue) {
362407
assert sharedPreferencesForAuth.getAll().keySet().size() > 0;
363408
assert sharedPreferencesForAuthEncryptionMaterials.getAll().keySet().size() > 0;
364409

365-
assertEquals("proofKey",
410+
assertEquals(proofKeyValue,
366411
LocalDataManager.getCachedProofKey(awsKeyValueStore, InstrumentationRegistry.getTargetContext(), "key"));
367-
assertEquals(setFromString("email,profile,openid"),
412+
assertEquals(scopesValue == null ? new HashSet<String>() : setFromString(scopesValue),
368413
LocalDataManager.getCachedScopes(awsKeyValueStore, InstrumentationRegistry.getTargetContext(), "key"));
369414
}
370415

aws-android-sdk-cognitoauth/src/main/java/com/amazonaws/mobileconnectors/cognitoauth/AuthClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ public void onServiceDisconnected(final ComponentName name) {
618618
public void onNavigationEvent(final int navigationEvent, final Bundle extras) {
619619
super.onNavigationEvent(navigationEvent, extras);
620620
if (navigationEvent == ClientConstants.CHROME_NAVIGATION_CANCELLED) {
621-
Log.i("AuthClient", "customTab hidden callback");
621+
Log.i("AuthClient", "customTab hidden callback, code has already been received: " + receivedCodeTabShouldBeHidden);
622622
if (!receivedCodeTabShouldBeHidden) {
623623
userHandler.onFailure(new AuthNavigationException("user cancelled"));
624624
receivedCodeTabShouldBeHidden = false;

aws-android-sdk-cognitoauth/src/main/java/com/amazonaws/mobileconnectors/cognitoauth/util/LocalDataManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ static String setToString(Set<String> stringSet) {
505505
}
506506

507507
static Set<String> setFromString(String str) {
508-
final HashSet<String> stringSet = new HashSet<>();
508+
final HashSet<String> stringSet = new HashSet<String>();
509509
if (StringUtils.isBlank(str)) {
510510
return stringSet;
511511
}

0 commit comments

Comments
 (0)