@@ -209,20 +209,29 @@ func TestStoreSetRootKey(t *testing.T) {
209
209
}
210
210
211
211
// TestStoreChangePassword tests that the password for the store can be changed
212
- // without changing the root key.
212
+ // without changing the root key. The test also demonstrates that currently,
213
+ // this change is only applied to the root key at the default root key ID
214
+ // location and not to other root keys. This will be fixed in an upcoming
215
+ // commit.
213
216
func TestStoreChangePassword (t * testing.T ) {
214
217
tempDir , store := newTestStore (t )
215
218
216
- // The store must be unlocked to replace the root key .
219
+ // The store must be unlocked to replace the root keys .
217
220
err := store .ChangePassword (nil , nil )
218
221
require .Equal (t , macaroons .ErrStoreLocked , err )
219
222
220
- // Unlock the DB and read the current root key. This will need to stay
221
- // the same after changing the password for the test to succeed.
223
+ // Unlock the DB and read the current default root key and one other
224
+ // non-default root key. Both of these should stay the same after
225
+ // changing the password but currently only the default root key is
226
+ // re-encrypted correclty.
222
227
pw := []byte ("weks" )
223
228
err = store .CreateUnlock (& pw )
224
229
require .NoError (t , err )
225
- rootKey , _ , err := store .RootKey (defaultRootKeyIDContext )
230
+
231
+ rootKey1 , _ , err := store .RootKey (defaultRootKeyIDContext )
232
+ require .NoError (t , err )
233
+
234
+ _ , _ , err = store .RootKey (nonDefaultRootKeyIDContext )
226
235
require .NoError (t , err )
227
236
228
237
// Both passwords must be set.
@@ -256,9 +265,13 @@ func TestStoreChangePassword(t *testing.T) {
256
265
err = store .CreateUnlock (& newPw )
257
266
require .NoError (t , err )
258
267
259
- // Finally read the root key from the DB using the new password and
260
- // make sure the root key stayed the same.
268
+ // Finally, read the root keys from the DB using the new password and
269
+ // make sure the default root key stayed the same but that the
270
+ // non-default root key could not be decrypted.
261
271
rootKeyDb , _ , err := store .RootKey (defaultRootKeyIDContext )
262
272
require .NoError (t , err )
263
- require .Equal (t , rootKey , rootKeyDb )
273
+ require .Equal (t , rootKey1 , rootKeyDb )
274
+
275
+ _ , _ , err = store .RootKey (nonDefaultRootKeyIDContext )
276
+ require .ErrorContains (t , err , "unable to decrypt" )
264
277
}
0 commit comments