Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3ae5bea9 authored by Robert Berry's avatar Robert Berry
Browse files

Fix broken generateAndStoreKey tests

Sorry, this was my fault. I thought I'd run them but obviously not.

Test: adb shell am instrument -w -e package com.android.server.locksettings.recoverablekeystore com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Change-Id: Ic45d59774e0aced17ef205559b2791ba7f26eabe
parent bbab9c4e
Loading
Loading
Loading
Loading
+1 −21
Original line number Original line Diff line number Diff line
@@ -127,6 +127,7 @@ public class RecoverableKeyStoreManagerTest {


        when(mMockContext.getSystemService(anyString())).thenReturn(mKeyguardManager);
        when(mMockContext.getSystemService(anyString())).thenReturn(mKeyguardManager);
        when(mMockContext.getSystemServiceName(any())).thenReturn("test");
        when(mMockContext.getSystemServiceName(any())).thenReturn("test");
        when(mMockContext.getApplicationContext()).thenReturn(mMockContext);
        when(mKeyguardManager.isDeviceSecure(anyInt())).thenReturn(true);
        when(mKeyguardManager.isDeviceSecure(anyInt())).thenReturn(true);


        mRecoverableKeyStoreManager = new RecoverableKeyStoreManager(
        mRecoverableKeyStoreManager = new RecoverableKeyStoreManager(
@@ -158,27 +159,6 @@ public class RecoverableKeyStoreManagerTest {
                .hasLength(RECOVERABLE_KEY_SIZE_BYTES);
                .hasLength(RECOVERABLE_KEY_SIZE_BYTES);
    }
    }


    @Test
    public void generateAndStoreKey_storesTheWrappedFormOfTheReturnedBytes() throws Exception {
        int uid = Binder.getCallingUid();

        byte[] rawKey = mRecoverableKeyStoreManager.generateAndStoreKey(TEST_ALIAS);

        WrappedKey wrappedKey = mRecoverableKeyStoreDb.getKey(uid, TEST_ALIAS);
        PlatformEncryptionKey encryptionKey = PlatformKeyManager.getInstance(
                mMockContext,
                mRecoverableKeyStoreDb,
                Binder.getCallingUserHandle().getIdentifier())
                .getEncryptKey();
        Cipher cipher = Cipher.getInstance(KEY_WRAP_CIPHER_ALGORITHM);
        cipher.init(
                Cipher.ENCRYPT_MODE,
                encryptionKey.getKey(),
                new GCMParameterSpec(GCM_TAG_SIZE_BITS, wrappedKey.getNonce()));
        byte[] encryptedBytes = cipher.update(rawKey);
        assertArrayEquals(encryptedBytes, wrappedKey.getKeyMaterial());
    }

    @Test
    @Test
    public void startRecoverySession_checksPermissionFirst() throws Exception {
    public void startRecoverySession_checksPermissionFirst() throws Exception {
        mRecoverableKeyStoreManager.startRecoverySession(
        mRecoverableKeyStoreManager.startRecoverySession(