Skip to content

Commit 3e1af13

Browse files
change: [DPS-35843] - Create destination, validate if host and bucket name match (#13176)
1 parent 617e933 commit 3e1af13

File tree

7 files changed

+47
-7
lines changed

7 files changed

+47
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Tests
3+
---
4+
5+
Mock Destination data update values ([#13176](https://github.com/linode/manager/pull/13176))

packages/manager/cypress/support/constants/delivery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const mockDestinationPayload: CreateDestinationPayload = {
1414
label: randomLabel(),
1515
type: destinationType.AkamaiObjectStorage,
1616
details: {
17-
host: randomString(),
18-
bucket_name: randomLabel(),
17+
host: 'test-bucket-name.host.com',
18+
bucket_name: 'test-bucket-name',
1919
access_key_id: randomString(),
2020
access_key_secret: randomString(),
2121
path: '/',

packages/manager/src/factories/delivery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const destinationFactory = Factory.Sync.makeFactory<Destination>({
77
details: {
88
access_key_id: 'Access Id',
99
bucket_name: 'destinations-bucket-name',
10-
host: '3000',
10+
host: 'destinations-bucket-name.host.com',
1111
path: 'file',
1212
},
1313
id: Factory.each((id) => id),

packages/manager/src/features/Delivery/Destinations/DestinationForm/DestinationEdit.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('DestinationEdit', () => {
5151
await waitFor(() => {
5252
assertInputHasValue('Destination Name', 'Destination 123');
5353
});
54-
assertInputHasValue('Host', '3000');
54+
assertInputHasValue('Host', 'destinations-bucket-name.host.com');
5555
assertInputHasValue('Bucket', 'destinations-bucket-name');
5656
assertInputHasValue('Access Key ID', 'Access Id');
5757
assertInputHasValue('Secret Access Key', '');

packages/manager/src/features/Delivery/Streams/StreamForm/StreamEdit.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('StreamEdit', () => {
6363
assertInputHasValue('Destination Name', 'Destination 1');
6464

6565
// Host:
66-
expect(screen.getByText('3000')).toBeVisible();
66+
expect(screen.getByText('destinations-bucket-name.host.com')).toBeVisible();
6767
// Bucket:
6868
expect(screen.getByText('destinations-bucket-name')).toBeVisible();
6969
// Access Key ID:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/validation": Changed
3+
---
4+
5+
Logs Destination Form - add matching host and bucket name validation ([#13176](https://github.com/linode/manager/pull/13176))

packages/validation/src/delivery.schema.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,26 @@ const customHTTPsDetailsSchema = object({
5757
endpoint_url: string().max(maxLength, maxLengthMessage).required(),
5858
});
5959

60+
const hostRgx =
61+
// eslint-disable-next-line sonarjs/slow-regex
62+
/(?<bucket>[a-z0-9-.]+)\.(?:s3(?:-accesspoint)?\.[a-z0-9-]+\.amazonaws\.com|(?!devcloud\.)[a-z0-9-]+\.(?:devcloud\.)?linodeobjects\.com)/;
63+
6064
const akamaiObjectStorageDetailsBaseSchema = object({
61-
host: string().max(maxLength, maxLengthMessage).required('Host is required.'),
65+
host: string()
66+
.max(maxLength, maxLengthMessage)
67+
.required('Host is required.')
68+
.test(
69+
'host-must-match-with-bucket-name-if-provided',
70+
'Bucket name provided as a part of the host must be the same as the bucket.',
71+
(value, ctx) => {
72+
if (ctx.parent.bucket_name) {
73+
const groups = hostRgx.exec(value)?.groups;
74+
return groups ? groups.bucket === ctx.parent.bucket_name : true;
75+
}
76+
77+
return true;
78+
},
79+
),
6280
bucket_name: string()
6381
.required('Bucket name is required.')
6482
.min(3, 'Bucket name must be between 3 and 63 characters.')
@@ -71,7 +89,19 @@ const akamaiObjectStorageDetailsBaseSchema = object({
7189
/^(?!.*[.-]{2})[a-z0-9.-]+$/,
7290
'Bucket name must contain only lowercase letters, numbers, periods (.), and hyphens (-). Adjacent periods and hyphens are not allowed.',
7391
)
74-
.max(63, 'Bucket name must be between 3 and 63 characters.'),
92+
.max(63, 'Bucket name must be between 3 and 63 characters.')
93+
.test(
94+
'bucket-name-same-in-host-if-provided',
95+
'Bucket must match the bucket name used in the host prefix.',
96+
(value, ctx) => {
97+
if (ctx.parent.host) {
98+
const groups = hostRgx.exec(ctx.parent.host)?.groups;
99+
return groups ? groups.bucket === value : true;
100+
}
101+
102+
return true;
103+
},
104+
),
75105
path: string().max(maxLength, maxLengthMessage).defined(),
76106
access_key_id: string()
77107
.max(maxLength, maxLengthMessage)

0 commit comments

Comments
 (0)