Skip to content

Commit 4cac99c

Browse files
authored
Merge pull request #45 from screwdriver-cd/buffer
fix: add buffer for JWT expiration time
2 parents 3dc7bb1 + 1165a56 commit 4cac99c

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ artifacts/
33
npm-debug.log
44
.DS_STORE
55
.*.swp
6+
.nyc*

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const executorSchema = dataSchema.plugins.executor;
77
const request = require('requestretry');
88
const jwt = require('jsonwebtoken');
99
const DEFAULT_BUILD_TIMEOUT = 90; // in minutes
10+
const DEFAULT_BUILD_TIMEOUT_BUFFER = 30; // in minutes
1011

1112
/**
1213
* Validate the config using the schema
@@ -160,7 +161,7 @@ class Executor {
160161
const options = {
161162
uri: `${config.apiUri}/v4/builds/${config.buildId}/token`,
162163
method: 'POST',
163-
body: { buildTimeout },
164+
body: { buildTimeout: buildTimeout + DEFAULT_BUILD_TIMEOUT_BUFFER },
164165
headers: { Authorization: `Bearer ${config.token}` },
165166
strictSSL: true,
166167
json: true

test/index.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const mockery = require('mockery');
66
const Joi = require('joi');
77
const jwt = require('jsonwebtoken');
88
const DEFAULT_BUILD_TIMEOUT = 90; // in minutes
9+
const DEFAULT_BUILD_TIMEOUT_BUFFER = 30; // in minutes
910

1011
describe('index test', () => {
1112
let instance;
@@ -164,6 +165,7 @@ describe('index test', () => {
164165
let postConfig;
165166
let options;
166167
let buildTimeout;
168+
let buildTimeoutWithBuffer;
167169
let fakeResponse;
168170
let token;
169171

@@ -175,10 +177,11 @@ describe('index test', () => {
175177
token
176178
};
177179
buildTimeout = 150;
180+
buildTimeoutWithBuffer = buildTimeout + DEFAULT_BUILD_TIMEOUT_BUFFER;
178181
options = {
179182
uri: `${postConfig.apiUri}/v4/builds/${postConfig.buildId}/token`,
180183
method: 'POST',
181-
body: { buildTimeout },
184+
body: { buildTimeout: buildTimeoutWithBuffer },
182185
headers: { Authorization: `Bearer ${postConfig.token}` },
183186
strictSSL: true,
184187
json: true
@@ -200,7 +203,7 @@ describe('index test', () => {
200203
});
201204

202205
it('succeeds to exchange temporal JWT to build JWT without buildTimeout args', async () => {
203-
options.body.buildTimeout = DEFAULT_BUILD_TIMEOUT;
206+
options.body.buildTimeout = DEFAULT_BUILD_TIMEOUT + DEFAULT_BUILD_TIMEOUT_BUFFER;
204207
requestMock.withArgs(options).resolves(fakeResponse);
205208

206209
await instance.exchangeTokenForBuild(postConfig).then((buildToken) => {

0 commit comments

Comments
 (0)