Skip to content

Commit 81012fc

Browse files
Merge pull request #2455 from Accenture/task/2454-prevent-upserts-with-keys-that-exceed-the-maximum-length
task/2454: show error during deploy if the key of an item exceed the max length
2 parents 56f6ba4 + ab3b62b commit 81012fc

9 files changed

Lines changed: 27 additions & 13 deletions

lib/metadataTypes/MetadataType.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,19 @@ class MetadataType {
753753
return false;
754754
}
755755

756+
/**
757+
* helper for {@link MetadataType.upsert} to enforce max key length
758+
*
759+
* @param {string} metadataKey key of metadata
760+
*/
761+
static enforceMaxKeyLength(metadataKey) {
762+
if (this.definition.maxKeyLength && metadataKey.length > this.definition.maxKeyLength) {
763+
throw new Error(
764+
`key exceeds maximum length of ${this.definition.maxKeyLength} characters for this type`
765+
);
766+
}
767+
}
768+
756769
/**
757770
* MetadataType upsert, after retrieving from target and comparing to check if create or update operation is needed.
758771
*
@@ -774,6 +787,7 @@ class MetadataType {
774787
// preDeployTasks parsing
775788
let deployableMetadata;
776789
try {
790+
this.enforceMaxKeyLength(metadataKey);
777791
metadataMap[metadataKey] = await this.validation(
778792
'deploy',
779793
metadataMap[metadataKey],

test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_htmlblock-matchName-create.asset-block-meta.html renamed to test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_html-matchNamFail.asset-block-meta.html

File renamed without changes.

test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_htmlblock-matchName-fail.asset-block-meta.json renamed to test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_html-matchNamFail.asset-block-meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"customerKey": "testExisting_asset_htmlblock-matchName-fail",
2+
"customerKey": "testExisting_asset_html-matchNamFail",
33
"assetType": {
44
"name": "htmlblock",
55
"displayName": "HTML Block"

test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_htmlblock-matchName-fail.asset-block-meta.html renamed to test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_html-matchName.asset-block-meta.html

File renamed without changes.

test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_htmlblock-matchName.asset-block-meta.json renamed to test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_html-matchName.asset-block-meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"customerKey": "testExisting_asset_htmlblock-matchName",
2+
"customerKey": "testExisting_asset_html-matchName",
33
"assetType": {
44
"name": "htmlblock",
55
"displayName": "HTML Block"

test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_htmlblock-matchName.asset-block-meta.html renamed to test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_html-matchNameAdd.asset-block-meta.html

File renamed without changes.

test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_htmlblock-matchName-create.asset-block-meta.json renamed to test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_html-matchNameAdd.asset-block-meta.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"customerKey": "testExisting_asset_htmlblock-matchName-create",
2+
"customerKey": "testExisting_asset_html-matchNameAdd",
33
"assetType": {
44
"name": "htmlblock",
55
"displayName": "HTML Block"
66
},
77
"fileProperties": {
8-
"fileName": "testExisting_htmlblock_matchName-create"
8+
"fileName": "testExisting_asset_html-matchNameAdd"
99
},
10-
"name": "testExisting_htmlblock_matchName-create",
10+
"name": "testExisting_asset_html-matchNameAdd",
1111
"owner": {
1212
"email": "joern.berkefeld@accenture.com",
1313
"name": "Jörn Berkefeld (ASGR)"

test/resources/9999999/asset/v1/content/assets/1295064/patch-response.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": 1295064,
3-
"customerKey": "testExisting_asset_htmlblock-matchName",
3+
"customerKey": "testExisting_asset_html-matchName",
44
"objectID": "26fdf503-eeed-49eb-b428-cb3b4bc2ba48",
55
"assetType": {
66
"id": 196,

test/type.asset.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ describe('type: asset', () => {
443443
const deployResult = await handler.deploy(
444444
'testInstance/testBU',
445445
['asset'],
446-
['testExisting_asset_htmlblock-matchName']
446+
['testExisting_asset_html-matchName']
447447
);
448448
// THEN
449449
assert.equal(process.exitCode, 0, 'deploy should not have thrown an error');
@@ -464,8 +464,8 @@ describe('type: asset', () => {
464464
);
465465
assert.equal(
466466
upsertCallout?.customerKey,
467-
'testExisting_asset_htmlblock-matchName',
468-
'customerKey should be testExisting_asset_htmlblock-matchName'
467+
'testExisting_asset_html-matchName',
468+
'customerKey should be testExisting_asset_html-matchName'
469469
);
470470
assert.equal(
471471
upsertCallout?.id,
@@ -487,7 +487,7 @@ describe('type: asset', () => {
487487
const deployResult = await handler.deploy(
488488
'testInstance/testBU',
489489
['asset'],
490-
['testExisting_asset_htmlblock-matchName-fail']
490+
['testExisting_asset_html-matchNamFail']
491491
);
492492
// THEN
493493
assert.equal(process.exitCode, 1, 'deploy should have thrown an error');
@@ -518,7 +518,7 @@ describe('type: asset', () => {
518518
const deployResult = await handler.deploy(
519519
'testInstance/testBU',
520520
['asset'],
521-
['testExisting_asset_htmlblock-matchName-create']
521+
['testExisting_asset_html-matchNameAdd']
522522
);
523523
// THEN
524524
assert.equal(process.exitCode, 0, 'deploy should not have thrown an error');
@@ -535,8 +535,8 @@ describe('type: asset', () => {
535535
const upsertCallout = testUtils.getRestCallout('post', '/asset/v1/content/assets/');
536536
assert.equal(
537537
upsertCallout?.customerKey,
538-
'testExisting_asset_htmlblock-matchName-create',
539-
'asset.customerKey should be testExisting_asset_htmlblock-matchName-create'
538+
'testExisting_asset_html-matchNameAdd',
539+
'asset.customerKey should be testExisting_asset_html-matchNameAdd'
540540
);
541541
assert.equal(
542542
upsertCallout?.id,

0 commit comments

Comments
 (0)