Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v4-policy): add missing bucket field #1168

Merged
merged 3 commits into from
May 1, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix tests
  • Loading branch information
jkwlui committed May 1, 2020
commit 3cefae60276c38309624b98a8871ca60c292d11e
27 changes: 16 additions & 11 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2822,24 +2822,27 @@ describe('File', () => {
fakeTimer.restore();
});

const fieldsToConditions = (fields: object) =>
Object.entries(fields).map(([k, v]) => ({[k]: v}));

it('should create a signed policy', done => {
CONFIG.fields = {
'x-goog-meta-foo': 'bar',
};

const fields = {
...CONFIG.fields,
bucket: BUCKET.name,
const requiredFields = {
key: file.name,
'x-goog-date': '20200101T000000Z',
'x-goog-credential': `${CLIENT_EMAIL}/20200101/auto/storage/goog4_request`,
'x-goog-algorithm': 'GOOG4-RSA-SHA256',
};

const policy = {
conditions: Object.entries(fields).map(([key, value]) => ({
[key]: value,
})),
conditions: [
...fieldsToConditions(CONFIG.fields),
{bucket: BUCKET.name},
...fieldsToConditions(requiredFields),
],
expiration: dateFormat.format(
new Date(CONFIG.expires),
'YYYY-MM-DD[T]HH:mm:ss[Z]',
Expand All @@ -2852,6 +2855,12 @@ describe('File', () => {
const EXPECTED_SIGNATURE = Buffer.from(SIGNATURE, 'base64').toString(
'hex'
);
const EXPECTED_FIELDS = {
...CONFIG.fields,
...requiredFields,
'x-goog-signature': EXPECTED_SIGNATURE,
policy: EXPECTED_POLICY,
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
file.generateSignedPostPolicyV4(
Expand All @@ -2860,11 +2869,7 @@ describe('File', () => {
assert.ifError(err);
assert(res.url, `${STORAGE_POST_POLICY_BASE_URL}/${BUCKET.name}`);

assert.deepStrictEqual(res.fields, {
...fields,
'x-goog-signature': EXPECTED_SIGNATURE,
policy: EXPECTED_POLICY,
});
assert.deepStrictEqual(res.fields, EXPECTED_FIELDS);

const signStub = BUCKET.storage.authClient.sign;
assert.deepStrictEqual(
Expand Down