3636import com .amazonaws .regions .Regions ;
3737
3838import java .util .ArrayList ;
39+ import java .util .Arrays ;
40+ import java .util .HashSet ;
41+ import java .util .Set ;
3942
4043
4144@ RunWith (AndroidJUnit4 .class )
4245public class AWSKeyValueStoreMigrationIntegrationTest extends CoreIntegrationTestBase {
4346
4447 private static String TAG = CognitoCachingCredentialsProviderIntegrationTest .class .getSimpleName ();
48+ private static SharedPreferences sharedPreferencesForAuth ;
49+ private static final String SHARED_PREFERENCES_NAME = "com.amazonaws.android.auth" ;
4550
4651 private ArrayList <CognitoCachingCredentialsProvider > credentialsProviders =new ArrayList <CognitoCachingCredentialsProvider >();
4752 private CognitoCachingCredentialsProvider credentialsProvider ;
4853
49- private static SharedPreferences sharedPreferencesForAuth ;
5054 private String identityPoolId ;
5155 private long time ;
56+ private Set <String > stringSet ;
5257
5358 @ BeforeClass
5459 public static void setupBeforeClass () {
5560 sharedPreferencesForAuth = InstrumentationRegistry .getTargetContext ()
56- .getSharedPreferences ("com.amazonaws.android.auth" , Context .MODE_PRIVATE );
61+ .getSharedPreferences (SHARED_PREFERENCES_NAME , Context .MODE_PRIVATE );
5762 }
5863
5964 @ AfterClass
@@ -68,12 +73,14 @@ public static void tearDownAfterClass() {
6873 public void setUp () throws Exception {
6974 time = System .currentTimeMillis ();
7075 identityPoolId = getPackageConfigure ().getString ("identity_pool_id" );
76+ stringSet = new HashSet <>(Arrays .asList ("openid" , "profile" , "email" ));
7177 sharedPreferencesForAuth .edit ()
7278 .putString (identityPoolId + ".accessKey" , "accessKey" )
7379 .putString (identityPoolId + ".secretKey" , "secretKey" )
7480 .putString (identityPoolId + ".sessionToken" , "sessionToken" )
7581 .putString (identityPoolId + ".identityId" , "identityId" )
7682 .putLong (identityPoolId + ".expirationDate" , time )
83+ .putStringSet ("stringSet" , stringSet )
7784 .commit ();
7885 }
7986
@@ -89,14 +96,15 @@ public void tearDown() {
8996
9097 @ Test
9198 public void testCachedAWSCredentialsMigration () throws Exception {
92- Log .d (TAG , "SharedPreferences contents before migration for com.amazonaws.android.auth => " +
99+ Log .d (TAG , "SharedPreferences contents before migration for " + SHARED_PREFERENCES_NAME + " => " +
93100 sharedPreferencesForAuth .getAll ().toString ());
94101
95102 assertEquals ("accessKey" , sharedPreferencesForAuth .getString (identityPoolId + ".accessKey" , null ));
96103 assertEquals ("secretKey" , sharedPreferencesForAuth .getString (identityPoolId + ".secretKey" , null ));
97104 assertEquals ("sessionToken" , sharedPreferencesForAuth .getString (identityPoolId + ".sessionToken" , null ));
98105 assertEquals ("identityId" , sharedPreferencesForAuth .getString (identityPoolId + ".identityId" , null ));
99106 assertEquals (time , sharedPreferencesForAuth .getLong (identityPoolId + ".expirationDate" , 0 ));
107+ assertEquals (stringSet , sharedPreferencesForAuth .getStringSet ("stringSet" , null ));
100108
101109 credentialsProvider = new CognitoCachingCredentialsProvider (
102110 InstrumentationRegistry .getTargetContext (),
@@ -105,17 +113,20 @@ public void testCachedAWSCredentialsMigration() throws Exception {
105113 credentialsProviders .add (credentialsProvider );
106114
107115 AWSKeyValueStore awsKeyValueStore = new AWSKeyValueStore (InstrumentationRegistry .getTargetContext (),
108- "com.amazonaws.android.auth" ,
116+ SHARED_PREFERENCES_NAME ,
109117 true );
118+ assertNotNull (awsKeyValueStore );
110119
111- Log .d (TAG , "SharedPreferences contents after migration for com.amazonaws.android.auth => " +
120+ Log .d (TAG , "SharedPreferences contents after migration for " + SHARED_PREFERENCES_NAME + " => " +
112121 sharedPreferencesForAuth .getAll ().toString ());
113122
114123 assertEquals ("accessKey" , awsKeyValueStore .get (identityPoolId + ".accessKey" ));
115124 assertEquals ("secretKey" , awsKeyValueStore .get (identityPoolId + ".secretKey" ));
116125 assertEquals ("sessionToken" , awsKeyValueStore .get (identityPoolId + ".sessionToken" ));
117126 assertEquals ("identityId" , awsKeyValueStore .get (identityPoolId + ".identityId" ));
118127 assertEquals (String .valueOf (time ), awsKeyValueStore .get (identityPoolId + ".expirationDate" ));
128+ assertNotNull (awsKeyValueStore .get ("stringSet" ));
129+ verifyStringSet ();
119130
120131 credentialsProvider .clearCredentials ();
121132 credentialsProvider .clear ();
@@ -131,6 +142,13 @@ public void testCachedAWSCredentialsMigration() throws Exception {
131142 verifyCredentialsProviderClear ();
132143 }
133144
145+ private void verifyStringSet () {
146+ assertNotNull (sharedPreferencesForAuth .getString ("stringSet.encrypted" , null ));
147+ assertNotNull (sharedPreferencesForAuth .getString ("stringSet.encrypted.iv" , null ));
148+ assertNotNull (sharedPreferencesForAuth .getString ("stringSet.encrypted.keyvaluestoreversion" , null ));
149+ assertNull (sharedPreferencesForAuth .getString ("stringSet" , null ));
150+ }
151+
134152 private void verifySharedPreferencesContents () {
135153 assert sharedPreferencesForAuth .getAll ().keySet ().size () == credentialsProviders .size () * 5 ;
136154
0 commit comments