-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VLTCLT-51 Add client method to get or create encryption key id #447
Merged
bert-e
merged 1 commit into
development/7.10
from
improvement/VLTCLT-51/getOrCreateEncryptionKeyId
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
'use strict'; // eslint-disable-line | ||
|
||
const assert = require('assert'); | ||
const http = require('http'); | ||
const IAMClient = require('../../lib/IAMClient'); | ||
|
||
const encryptionKeyId = '9c07eb04-d85a-48c4-8bc4-87f5ca2b9d5d'; | ||
const canonicalId = '79a59dfb37cfe5b3b1b4e58734c14e02b6e9e081ca135a3b02e6b8cc993b6dc7'; | ||
|
||
const output = { | ||
canonicalId, | ||
encryptionKeyId, | ||
action: 'created', | ||
}; | ||
|
||
describe('getOrCreateEncryptionKeyId Test', () => { | ||
let server; | ||
let client; | ||
const handler = (req, res) => { | ||
res.writeHead(200); | ||
return res.end(JSON.stringify(output)); | ||
}; | ||
|
||
beforeEach('start server', done => { | ||
server = http.createServer(handler).listen(8500, () => { | ||
client = new IAMClient('127.0.0.1', 8500); | ||
done(); | ||
}).on('error', done); | ||
}); | ||
|
||
afterEach('stop server', () => { server.close(); }); | ||
|
||
it('should retrieve getOrCreateEncryptionKeyId response', done => { | ||
client.getOrCreateEncryptionKeyId(canonicalId, | ||
{ reqUid: '123' }, | ||
(err, response) => { | ||
assert(!err); | ||
assert.deepStrictEqual(response.message.body, output); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should throw error if canonical id is undefined', () => { | ||
assert.throws( | ||
() => client.getOrCreateEncryptionKeyId(undefined, { reqUid: '123' }, () => {}), err => { | ||
assert(err instanceof assert.AssertionError); | ||
assert.strictEqual(err.message, 'canonicalId need to be specified'); | ||
return true; | ||
}, | ||
); | ||
}); | ||
|
||
it('should throw error if canonical id is not a string', () => { | ||
assert.throws( | ||
() => client.getOrCreateEncryptionKeyId(0, { reqUid: '123' }, () => {}), err => { | ||
assert(err instanceof assert.AssertionError); | ||
assert.strictEqual(err.message, 'canonicalId should be a string'); | ||
return true; | ||
}, | ||
); | ||
}); | ||
|
||
it('should throw error if canonical id is an empty string', () => { | ||
assert.throws( | ||
() => client.getOrCreateEncryptionKeyId('', { reqUid: '123' }, () => {}), err => { | ||
assert(err instanceof assert.AssertionError); | ||
assert.strictEqual(err.message, 'canonicalId should not be empty string'); | ||
return true; | ||
}, | ||
); | ||
}); | ||
}); | ||
|
||
describe('getOrCreateEncryptionKeyId with server error', () => { | ||
let server; | ||
let client; | ||
const erroredHandler = (req, res) => { | ||
res.writeHead(200); | ||
const serverError = '<ErrorResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">' | ||
+ '<Error><Code>ServiceFailure</Code><Message>Server error: the request processing has ' | ||
+ 'failed because of an unknown error, exception or failure.</Message></Error>' | ||
+ '<RequestId>3ac25e70c649bd4a6394:897ac94c0240b2a65f96</RequestId></ErrorResponse>'; | ||
return res.end(serverError); | ||
}; | ||
|
||
beforeEach('start server', done => { | ||
server = http.createServer(erroredHandler).listen(8500, () => { | ||
client = new IAMClient('127.0.0.1', 8500); | ||
done(); | ||
}).on('error', done); | ||
}); | ||
|
||
afterEach('stop server', () => { server.close(); }); | ||
|
||
it('should return an error', done => { | ||
client.getOrCreateEncryptionKeyId(canonicalId, | ||
{ reqUid: '123' }, | ||
(err, response) => { | ||
assert(!err); | ||
assert(response.message.body.ErrorResponse); | ||
done(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is a POST to / doing what we want to do here? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, :) It uses an RPC (remote procedure call) protocol. All actions are sent to a single endpoint
'/'
and the payload specifies the action to do:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh I see. I'm not familiar with the vault API and I assumed it uses HTTP routes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This action doesn't exist for now I think