diff options
author | Sudheer Shanka <sudheersai@google.com> | 2020-05-26 18:10:09 -0700 |
---|---|---|
committer | Sudheer Shanka <sudheersai@google.com> | 2020-05-27 11:41:34 -0700 |
commit | 8992c0514f3d1447656d560e7f446cc3c52d98fc (patch) | |
tree | 8f2d9d4dc0756fa6ebdfb5705b4ca7dab26c0b71 /tests/BlobStoreTestUtils/src | |
parent | 80a18c0a7bd847824def2be77dc4abcf0f109506 (diff) |
Don't allow expired blobs to be accessed.
Bug: 147722548
Test: atest --test-mapping apex/blobstore
Change-Id: I7294124ba5ce3dcf42a0e7e9858311b1604ae185
Diffstat (limited to 'tests/BlobStoreTestUtils/src')
-rw-r--r-- | tests/BlobStoreTestUtils/src/com/android/utils/blob/DummyBlobData.java | 14 | ||||
-rw-r--r-- | tests/BlobStoreTestUtils/src/com/android/utils/blob/Utils.java | 14 |
2 files changed, 20 insertions, 8 deletions
diff --git a/tests/BlobStoreTestUtils/src/com/android/utils/blob/DummyBlobData.java b/tests/BlobStoreTestUtils/src/com/android/utils/blob/DummyBlobData.java index 371375c0d932..4a0ca664049a 100644 --- a/tests/BlobStoreTestUtils/src/com/android/utils/blob/DummyBlobData.java +++ b/tests/BlobStoreTestUtils/src/com/android/utils/blob/DummyBlobData.java @@ -42,6 +42,7 @@ public class DummyBlobData { private final File mFile; private final long mFileSize; private final CharSequence mLabel; + private final long mExpiryDurationMs; byte[] mFileDigest; long mExpiryTimeMs; @@ -51,6 +52,7 @@ public class DummyBlobData { mFile = new File(builder.getContext().getFilesDir(), builder.getFileName()); mFileSize = builder.getFileSize(); mLabel = builder.getLabel(); + mExpiryDurationMs = builder.getExpiryDurationMs(); } public static class Builder { @@ -59,6 +61,7 @@ public class DummyBlobData { private long mFileSize = DEFAULT_SIZE_BYTES; private CharSequence mLabel = "Test label"; private String mFileName = "blob_" + System.nanoTime(); + private long mExpiryDurationMs = TimeUnit.DAYS.toMillis(1); public Builder(Context context) { mContext = context; @@ -104,6 +107,15 @@ public class DummyBlobData { return mFileName; } + public Builder setExpiryDurationMs(long durationMs) { + mExpiryDurationMs = durationMs; + return this; + } + + public long getExpiryDurationMs() { + return mExpiryDurationMs; + } + public DummyBlobData build() { return new DummyBlobData(this); } @@ -114,7 +126,7 @@ public class DummyBlobData { writeRandomData(file, mFileSize); } mFileDigest = FileUtils.digest(mFile, "SHA-256"); - mExpiryTimeMs = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1); + mExpiryTimeMs = System.currentTimeMillis() + mExpiryDurationMs; } public BlobHandle getBlobHandle() throws Exception { diff --git a/tests/BlobStoreTestUtils/src/com/android/utils/blob/Utils.java b/tests/BlobStoreTestUtils/src/com/android/utils/blob/Utils.java index 7cf58e1682bf..b9bd661dfd67 100644 --- a/tests/BlobStoreTestUtils/src/com/android/utils/blob/Utils.java +++ b/tests/BlobStoreTestUtils/src/com/android/utils/blob/Utils.java @@ -18,7 +18,6 @@ package com.android.utils.blob; import static com.google.common.truth.Truth.assertThat; -import android.app.Instrumentation; import android.app.blob.BlobHandle; import android.app.blob.BlobStoreManager; import android.app.blob.LeaseInfo; @@ -27,6 +26,7 @@ import android.content.res.Resources; import android.os.ParcelFileDescriptor; import android.util.Log; +import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.uiautomator.UiDevice; import java.io.FileInputStream; @@ -149,14 +149,14 @@ public class Utils { assertThat(leaseInfo.getDescription()).isEqualTo(description); } - public static void triggerIdleMaintenance(Instrumentation instrumentation) throws IOException { - runShellCmd(instrumentation, "cmd blob_store idle-maintenance"); + public static void triggerIdleMaintenance() throws IOException { + runShellCmd("cmd blob_store idle-maintenance"); } - private static String runShellCmd(Instrumentation instrumentation, - String cmd) throws IOException { - final UiDevice uiDevice = UiDevice.getInstance(instrumentation); - final String result = uiDevice.executeShellCommand(cmd); + public static String runShellCmd(String cmd) throws IOException { + final UiDevice uiDevice = UiDevice.getInstance( + InstrumentationRegistry.getInstrumentation()); + final String result = uiDevice.executeShellCommand(cmd).trim(); Log.i(TAG, "Output of '" + cmd + "': '" + result + "'"); return result; } |