Skip to content

Commit

Permalink
Merge b24719f into 9d361c6
Browse files Browse the repository at this point in the history
  • Loading branch information
rockuw committed Jun 16, 2017
2 parents 9d361c6 + b24719f commit a1db822
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions es5/client.js
Expand Up @@ -73,6 +73,15 @@ var Client = function () {

this.accessKeyID = accessKeyID;

if (this.accessKeyID.startsWith('STS')) {
console.log('hello: %j', this.accessKeyID);
this.securityToken = config.securityToken;
console.log('world: %j', this.securityToken);
if (!this.securityToken) {
throw new TypeError('"config.securityToken" must be passed in for STS');
}
}

var accessKeySecret = config.accessKeySecret;
if (!accessKeySecret) {
throw new TypeError('"config.accessKeySecret" must be passed in');
Expand Down
7 changes: 7 additions & 0 deletions lib/client.js
Expand Up @@ -61,6 +61,13 @@ class Client {

this.accessKeyID = accessKeyID;

if (this.accessKeyID.startsWith('STS')) {
this.securityToken = config.securityToken;
if (!this.securityToken) {
throw new TypeError('"config.securityToken" must be passed in for STS');
}
}

const accessKeySecret = config.accessKeySecret;
if (!accessKeySecret) {
throw new TypeError('"config.accessKeySecret" must be passed in');
Expand Down
18 changes: 18 additions & 0 deletions test/client.test.js
Expand Up @@ -41,6 +41,14 @@ describe('client test', function () {
});
}).to.throwException(/"config.region" must be passed in/);

expect(() => {
new FunctionComputeClient('accountid', {
accessKeyID: 'STS.accessKeyID',
accessKeySecret: 'accessKeySecret',
region: 'cn-shanghai',
});
}).to.throwException(/"config.securityToken" must be passed in for STS/);

var client;
client = new FunctionComputeClient('accountid', {
accessKeyID: 'accessKeyID',
Expand All @@ -49,6 +57,14 @@ describe('client test', function () {
});
expect(client.endpoint).to.be('http://accountid.fc.cn-shanghai.aliyuncs.com');

client = new FunctionComputeClient('accountid', {
accessKeyID: 'STS.accessKeyID',
accessKeySecret: 'accessKeySecret',
region: 'cn-shanghai',
securityToken: 'securityToken',
});
expect(client.endpoint).to.be('http://accountid.fc.cn-shanghai.aliyuncs.com');

client = new FunctionComputeClient('accountid', {
accessKeyID: 'accessKeyID',
accessKeySecret: 'accessKeySecret',
Expand Down Expand Up @@ -319,6 +335,8 @@ describe('client test', function () {
});
expect(trigger).to.be.ok();
expect(trigger).to.have.property('triggerName', triggerName);
// sleep a while for trigger meta to sync
await new Promise(res => setTimeout(res, 30 * 1000));
});

it('listTriggers should ok', async function() {
Expand Down

0 comments on commit a1db822

Please sign in to comment.