Skip to content

Commit

Permalink
Merge pull request #262 from bcgov/child-bucket
Browse files Browse the repository at this point in the history
allow forward slashes in child bucket sub-path
  • Loading branch information
jatindersingh93 authored May 29, 2024
2 parents 5b74516 + 9f7d1d4 commit 3154930
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
4 changes: 2 additions & 2 deletions app/src/controllers/invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const controller = {
let resource, type;

try {
// Reject if expiresAt is more than 7 days away
const maxExpiresAt = Math.floor(Date.now() / 1000) + 691199;
// Reject if expiresAt is more than 30 days away
const maxExpiresAt = Math.floor(Date.now() / 1000) + 2592000;
if (req.body.expiresAt && req.body.expiresAt > maxExpiresAt) {
const limit = new Date(maxExpiresAt * 1000).toISOString();
const msg = `"expiresAt" must be less than "${limit}"`;
Expand Down
6 changes: 3 additions & 3 deletions app/src/docs/v1.api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2411,9 +2411,9 @@ components:
example: Geospatial Maps
subKey:
type: string
description: The desired S3 child directory name. Must not include `/`.
description: a path relative to the parent bucket to the 'directory' you are mounting
maxLength: 255
example: child
example: canada/bc/maps
Request-CreateInvite:
title: Request Create Invite
type: object
Expand All @@ -2437,7 +2437,7 @@ components:
type: integer
description: >-
Optional desired unix epoch time for when this invitation should
expire. Defaults to 24 hours from now if unspecified.
expire. Defaults to 24 hours from now if unspecified. Maximum of 30 days from now.
example: 1710000000
objectId:
type: string
Expand Down
2 changes: 1 addition & 1 deletion app/src/validators/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const schema = {
createBucketChild: {
body: Joi.object().keys({
bucketName: Joi.string().max(255).required(),
subKey: Joi.string().max(255).trim().strict().pattern(/^[^/]+$/).required()
subKey: Joi.string().max(255).trim().strict().required()
}).required(),
params: Joi.object({
bucketId: type.uuidv4
Expand Down
17 changes: 2 additions & 15 deletions app/tests/unit/validators/bucket.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('createBucketChild', () => {

it('trims whitespace', () => {
expect(Array.isArray(subKey.rules)).toBeTruthy();
expect(subKey.rules).toHaveLength(3);
expect(subKey.rules).toHaveLength(2);
expect(subKey.rules).toEqual(expect.arrayContaining([
expect.objectContaining({
args: {
Expand All @@ -170,7 +170,7 @@ describe('createBucketChild', () => {

it('has a max length of 255', () => {
expect(Array.isArray(subKey.rules)).toBeTruthy();
expect(subKey.rules).toHaveLength(3);
expect(subKey.rules).toHaveLength(2);
expect(subKey.rules).toEqual(expect.arrayContaining([
expect.objectContaining({
args: {
Expand All @@ -181,19 +181,6 @@ describe('createBucketChild', () => {
]));
});

it('has a regex', () => {
expect(Array.isArray(subKey.rules)).toBeTruthy();
expect(subKey.rules).toHaveLength(3);
expect(subKey.rules).toEqual(expect.arrayContaining([
expect.objectContaining({
args: {
regex: '/^[^/]+$/'
},
name: 'pattern'
}),
]));
});

it('is strict', () => {
expect(subKey.preferences).toBeTruthy();
expect(subKey.preferences.convert).toBeFalsy();
Expand Down

0 comments on commit 3154930

Please sign in to comment.