Skip to content
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

fix: await http response in AWS EKS detector #2076

Merged
merged 2 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class AwsEksDetector implements Detector {
await AwsEksDetector.fileAccessAsync(this.K8S_TOKEN_PATH);
const k8scert = await AwsEksDetector.readFileAsync(this.K8S_CERT_PATH);

if (!this._isEks(k8scert)) {
if (!(await this._isEks(k8scert))) {
return Resource.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ describe('awsEksDetector', () => {
});

describe('on unsuccesful request', () => {
it('should throw when receiving error response code', async () => {
const expectedError = new Error('EKS metadata api request timed out.');
it('should return an empty resource when timed out', async () => {
fileStub = sinon
.stub(AwsEksDetector, 'fileAccessAsync' as any)
.resolves();
Expand All @@ -265,17 +264,14 @@ describe('awsEksDetector', () => {
.delayConnection(2500)
.reply(200, () => mockedAwsAuth);

try {
await awsEksDetector.detect();
} catch (err) {
assert.deepStrictEqual(err, expectedError);
}

const resource: Resource = await awsEksDetector.detect();
scope.done();
});

it('should return an empty resource when timed out', async () => {
const expectedError = new Error('Failed to load page, status code: 404');
assert.ok(resource);
assertEmptyResource(resource);
}).timeout(awsEksDetector.TIMEOUT_MS + 100);

it('should return an empty resource when receiving error response code', async () => {
fileStub = sinon
.stub(AwsEksDetector, 'fileAccessAsync' as any)
.resolves();
Expand All @@ -291,13 +287,11 @@ describe('awsEksDetector', () => {
.matchHeader('Authorization', k8s_token)
.reply(404, () => new Error());

try {
await awsEksDetector.detect();
} catch (err) {
assert.deepStrictEqual(err, expectedError);
}

const resource: Resource = await awsEksDetector.detect();
scope.done();

assert.ok(resource);
assertEmptyResource(resource);
});
});
});