Skip to content

Commit

Permalink
Adds new tests to check backwards compatibiltiy
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
  • Loading branch information
DarshitChanpura committed Dec 15, 2023
1 parent 4c84726 commit a8f3476
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ In order to deploy both the stacks the user needs to provide a set of required a
|------------------------|:------------|:--------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| distVersion | Required | string | The OpenSearch distribution version (released/un-released) the user wants to deploy |
| securityDisabled | Required | boolean | Enable or disable security plugin |
| adminPassword | Optional | string | This value is required when security plugin is enabled |
| adminPassword | Optional | string | This value is required when security plugin is enabled and the cluster version is >= 2.12 |
| minDistribution | Required | boolean | Is it the minimal OpenSearch distribution with no security and plugins |
| distributionUrl | Required | string | OpenSearch tar distribution url |
| cpuArch | Required | string | CPU platform for EC2, could be either `x64` or `arm64` |
Expand Down
4 changes: 2 additions & 2 deletions lib/os-cluster-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export class OsClusterEntrypoint {
const security = securityDisabled === 'true';

// adminPassword is required if security is enabled and demo config is to be run
const adminPassword: String = security ? `${scope.node.tryGetContext('adminPassword')}` : "";
if (security && (adminPassword === null || adminPassword === "")) {
const adminPassword: String = security ? `${scope.node.tryGetContext('adminPassword')}` : "";
if (!security && Number.parseFloat(distVersion) >= 2.12 && (adminPassword === null || adminPassword === "")) {
throw new Error('adminPassword parameter is required to be set when security is enabled');
}

Expand Down
44 changes: 37 additions & 7 deletions test/os-cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ test('Throw error on incorrect JSON', () => {
}
});

test('Throw error when security is enabled and adminPassword is not defined', () => {
test('Throw error when security is enabled and adminPassword is not defined and dist version is greater than or equal to 2.12', () => {
const app = new App({
context: {
securityDisabled: false,
Expand All @@ -539,16 +539,16 @@ test('Throw error when security is enabled and adminPassword is not defined', ()
cpuArch: 'x64',
singleNodeCluster: false,
dashboardsUrl: 'www.example.com',
distVersion: '1.0.0',
distVersion: '3.0.0',
serverAccessType: 'ipv4',
restrictServerAccessTo: 'all',
additionalConfig: '{ "name": "John Doe", "age": 30, "email": "johndoe@example.com" }',
additionalOsdConfig: '{ "something.enabled": "true", "something_else.enabled": "false" }',
// eslint-disable-next-line max-len
customConfigFiles: '{"test/data/config.yml": opensearch/config/opensearch-security/config.yml"}',
managerNodeCount: 0,
dataNodeCount: 3,
dataNodeStorage: 200,
customRoleArn: 'arn:aws:iam::12345678:role/customRoleName',
},
});
// WHEN

try {
const testStack = new OsClusterEntrypoint(app, {
env: { account: 'test-account', region: 'us-east-1' },
Expand All @@ -562,3 +562,33 @@ test('Throw error when security is enabled and adminPassword is not defined', ()
expect(error.message).toEqual('adminPassword parameter is required to be set when security is enabled');
}
});

test('Should not throw error when security is enabled and adminPassword is not defined and dist version is less than 2.12', () => {
const app = new App({
context: {
securityDisabled: false,
minDistribution: false,
distributionUrl: 'www.example.com',
cpuArch: 'x64',
singleNodeCluster: false,
dashboardsUrl: 'www.example.com',
distVersion: '1.0.0',
serverAccessType: 'ipv4',
restrictServerAccessTo: 'all',
managerNodeCount: 0,
dataNodeCount: 3,
dataNodeStorage: 200,
customRoleArn: 'arn:aws:iam::12345678:role/customRoleName',
},
});

// WHEN
const testStack = new OsClusterEntrypoint(app, {
env: { account: 'test-account', region: 'us-east-1' },
});

// THEN
expect(testStack.stacks).toHaveLength(2);

});

0 comments on commit a8f3476

Please sign in to comment.