Skip to content

Commit

Permalink
PROD-37017 Allow orka to accept s3 presigned URLs with region (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristosLabrou authored Mar 6, 2024
1 parent f81f2f1 commit f211edc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/initializers/joi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export const isOwnS3Path = (bucket: string, val: string): boolean => {
host.startsWith('s3.') &&
host.endsWith('.amazonaws.com') &&
pathname.startsWith(`/${bucket}/`);
return matchingProtocol && (s3Host || s3HostBucketInPath);
const s3HostContainsRegion =
host.startsWith(`${bucket}.s3`) &&
host.endsWith('.amazonaws.com') &&
host.split('.').length === 5;
return matchingProtocol && (s3Host || s3HostBucketInPath || s3HostContainsRegion);
} catch (e) {
logger.error(`Failed to parse url: ${val}`, e);
return false;
Expand Down
24 changes: 23 additions & 1 deletion test/initializers/joi.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import should = require('should');
import Joi from '../../src/initializers/joi';
import { isExpiredUrl } from '../../src/initializers/joi';
import { isExpiredUrl, isOwnS3Path } from '../../src/initializers/joi';
import * as sinon from 'sinon';

describe('joi extensions', function () {
Expand Down Expand Up @@ -259,4 +259,26 @@ describe('joi extensions', function () {
isExpired.map((x) => x.should.be.false());
});
});

describe('isOwnS3Path', function () {
it('should return true for valid s3 path', function () {
const isOwnPath = [
isOwnS3Path('some-bucket', 'https://s3.amazonaws.com/some-bucket/some-file-name'),
isOwnS3Path('some-bucket', 'https://some-bucket.s3.some-region-1.amazonaws.com/'),
isOwnS3Path('some-bucket', 'https://some-bucket.s3.amazonaws.com/'),
];
isOwnPath.map((x) => x.should.be.true());
});

it('should return false for invalid s3 path', function () {
const isOwnPath = [
isOwnS3Path('some-bucket', 'https://s3.amazonaws.com/some-other-bucket/some-file-name'),
isOwnS3Path('some-bucket', 'https://some-other-bucket.s3.some-region-1.amazonaws.com/'),
isOwnS3Path('some-bucket', 'https://some-other-bucket.s3.amazonaws.com/'),
isOwnS3Path('some-bucket', 'https://some-other-bucket.s3.some.deep.nested.subdomain.amazonaws.com/'),
isOwnS3Path('some-bucket', 'https://some-bucket.s3.some.deep.nested.subdomain.amazonaws.com/')
];
isOwnPath.map((x) => x.should.be.false());
});
});
});

0 comments on commit f211edc

Please sign in to comment.