Skip to content

Commit 4689e22

Browse files
committed
test update contract test
1 parent 30831ae commit 4689e22

File tree

2 files changed

+120
-119
lines changed

2 files changed

+120
-119
lines changed
Lines changed: 118 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33
import expect from 'expect';
4-
// import { OTLPAwsSpanExporter } from '../src/otlp-aws-span-exporter';
4+
import { OTLPAwsSpanExporter } from '../src/otlp-aws-span-exporter';
55
import * as sinon from 'sinon';
6-
import * as proxyquire from 'proxyquire';
6+
// import * as proxyquire from 'proxyquire';
77
import * as nock from 'nock';
88
import { getNodeVersion } from '../src/utils';
99

@@ -13,9 +13,9 @@ const AUTHORIZATION_HEADER = 'Authorization';
1313
const X_AMZ_DATE_HEADER = 'X-Amz-Date';
1414
const X_AMZ_SECURITY_TOKEN_HEADER = 'X-Amz-Security-Token';
1515

16-
const EXPECTED_AUTH_HEADER = 'AWS4-HMAC-SHA256 Credential=test_key/some_date/us-east-1/xray/aws4_request';
17-
const EXPECTED_AUTH_X_AMZ_DATE = 'some_date';
18-
const EXPECTED_AUTH_SECURITY_TOKEN = 'test_token';
16+
// const EXPECTED_AUTH_HEADER = 'AWS4-HMAC-SHA256 Credential=test_key/some_date/us-east-1/xray/aws4_request';
17+
// const EXPECTED_AUTH_X_AMZ_DATE = 'some_date';
18+
// const EXPECTED_AUTH_SECURITY_TOKEN = 'test_token';
1919

2020
const nodeVersion = getNodeVersion();
2121

@@ -25,7 +25,7 @@ if (nodeVersion >= 16) {
2525
describe('OTLPAwsSpanExporter', () => {
2626
let sandbox: sinon.SinonSandbox;
2727
let scope: nock.Scope;
28-
let mockModule: any;
28+
// let mockModule: any;
2929

3030
beforeEach(() => {
3131
sandbox = sinon.createSandbox();
@@ -36,138 +36,138 @@ if (nodeVersion >= 16) {
3636
return [200, ''];
3737
});
3838

39-
mockModule = proxyquire('../src/otlp-aws-span-exporter', {
40-
'@smithy/signature-v4': {
41-
SignatureV4: class MockSignatureV4 {
42-
sign(req: any) {
43-
req.headers = {
44-
...req.headers,
45-
[AUTHORIZATION_HEADER]: EXPECTED_AUTH_HEADER,
46-
[X_AMZ_DATE_HEADER]: EXPECTED_AUTH_X_AMZ_DATE,
47-
[X_AMZ_SECURITY_TOKEN_HEADER]: EXPECTED_AUTH_SECURITY_TOKEN,
48-
};
49-
50-
return req;
51-
}
52-
},
53-
},
54-
'@aws-sdk/credential-provider-node': {
55-
defaultProvider: () => async () => {
56-
return {
57-
accessKeyId: 'test_access_key',
58-
secretAccessKey: 'test_secret_key',
59-
};
60-
},
61-
},
62-
});
39+
// mockModule = proxyquire('../src/otlp-aws-span-exporter', {
40+
// '@smithy/signature-v4': {
41+
// SignatureV4: class MockSignatureV4 {
42+
// sign(req: any) {
43+
// req.headers = {
44+
// ...req.headers,
45+
// [AUTHORIZATION_HEADER]: EXPECTED_AUTH_HEADER,
46+
// [X_AMZ_DATE_HEADER]: EXPECTED_AUTH_X_AMZ_DATE,
47+
// [X_AMZ_SECURITY_TOKEN_HEADER]: EXPECTED_AUTH_SECURITY_TOKEN,
48+
// };
49+
50+
// return req;
51+
// }
52+
// },
53+
// },
54+
// '@aws-sdk/credential-provider-node': {
55+
// defaultProvider: () => async () => {
56+
// return {
57+
// accessKeyId: 'test_access_key',
58+
// secretAccessKey: 'test_secret_key',
59+
// };
60+
// },
61+
// },
62+
// });
6363
});
6464

6565
afterEach(() => {
6666
sandbox.restore();
6767
});
6868

69-
it('Should inject SigV4 Headers successfully', async () => {
70-
const exporter = new mockModule.OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT + XRAY_OTLP_ENDPOINT_PATH);
71-
72-
scope.on('request', (req, interceptor, body) => {
73-
const headers = req.headers;
74-
expect(headers).toHaveProperty(AUTHORIZATION_HEADER.toLowerCase());
75-
expect(headers).toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER.toLowerCase());
76-
expect(headers).toHaveProperty(X_AMZ_DATE_HEADER.toLowerCase());
77-
78-
expect(headers[AUTHORIZATION_HEADER.toLowerCase()]).toBe(EXPECTED_AUTH_HEADER);
79-
expect(headers[X_AMZ_SECURITY_TOKEN_HEADER.toLowerCase()]).toBe(EXPECTED_AUTH_SECURITY_TOKEN);
80-
expect(headers[X_AMZ_DATE_HEADER.toLowerCase()]).toBe(EXPECTED_AUTH_X_AMZ_DATE);
69+
// it('Should inject SigV4 Headers successfully', async () => {
70+
// const exporter = new mockModule.OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT + XRAY_OTLP_ENDPOINT_PATH);
8171

82-
expect(headers['content-type']).toBe('application/x-protobuf');
83-
expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
84-
});
72+
// scope.on('request', (req, interceptor, body) => {
73+
// const headers = req.headers;
74+
// expect(headers).toHaveProperty(AUTHORIZATION_HEADER.toLowerCase());
75+
// expect(headers).toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER.toLowerCase());
76+
// expect(headers).toHaveProperty(X_AMZ_DATE_HEADER.toLowerCase());
8577

86-
await exporter.export([], () => {});
87-
});
78+
// expect(headers[AUTHORIZATION_HEADER.toLowerCase()]).toBe(EXPECTED_AUTH_HEADER);
79+
// expect(headers[X_AMZ_SECURITY_TOKEN_HEADER.toLowerCase()]).toBe(EXPECTED_AUTH_SECURITY_TOKEN);
80+
// expect(headers[X_AMZ_DATE_HEADER.toLowerCase()]).toBe(EXPECTED_AUTH_X_AMZ_DATE);
8881

89-
// describe('Should not inject SigV4 headers if dependencies are missing', () => {
90-
// const dependencies = [
91-
// '@aws-sdk/credential-provider-node',
92-
// '@aws-crypto/sha256-js',
93-
// '@smithy/signature-v4',
94-
// '@smithy/protocol-http',
95-
// ];
96-
97-
// dependencies.forEach(dependency => {
98-
// it(`should not sign headers if missing dependency: ${dependency}`, async () => {
99-
// const exporter = new OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT + XRAY_OTLP_ENDPOINT_PATH);
100-
101-
// scope.on('request', (req, interceptor, body) => {
102-
// const headers = req.headers;
103-
// expect(headers).not.toHaveProperty(AUTHORIZATION_HEADER);
104-
// expect(headers).not.toHaveProperty(X_AMZ_DATE_HEADER);
105-
// expect(headers).not.toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER);
106-
107-
// expect(headers['content-type']).toBe('application/x-protobuf');
108-
// expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
109-
// });
110-
111-
// Object.keys(require.cache).forEach(key => {
112-
// delete require.cache[key];
113-
// });
114-
// const requireStub = sandbox.stub(require('module'), '_load');
115-
// requireStub.withArgs(dependency).throws(new Error(`Cannot find module '${dependency}'`));
116-
// requireStub.callThrough();
117-
118-
// await exporter.export([], () => {});
119-
// });
82+
// expect(headers['content-type']).toBe('application/x-protobuf');
83+
// expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
12084
// });
121-
// });
12285

123-
it('should not inject SigV4 headers if failure to sign headers', async () => {
124-
scope.on('request', (req, interceptor, body) => {
125-
const headers = req.headers;
126-
expect(headers).not.toHaveProperty(AUTHORIZATION_HEADER);
127-
expect(headers).not.toHaveProperty(X_AMZ_DATE_HEADER);
128-
expect(headers).not.toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER);
86+
// await exporter.export([], () => {});
87+
// });
12988

130-
expect(headers['content-type']).toBe('application/x-protobuf');
131-
expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
89+
describe('Should not inject SigV4 headers if dependencies are missing', () => {
90+
const dependencies = [
91+
'@aws-sdk/credential-provider-node',
92+
'@aws-crypto/sha256-js',
93+
'@smithy/signature-v4',
94+
'@smithy/protocol-http',
95+
];
96+
97+
dependencies.forEach(dependency => {
98+
it(`should not sign headers if missing dependency: ${dependency}`, async () => {
99+
const exporter = new OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT + XRAY_OTLP_ENDPOINT_PATH);
100+
101+
scope.on('request', (req, interceptor, body) => {
102+
const headers = req.headers;
103+
expect(headers).not.toHaveProperty(AUTHORIZATION_HEADER);
104+
expect(headers).not.toHaveProperty(X_AMZ_DATE_HEADER);
105+
expect(headers).not.toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER);
106+
107+
expect(headers['content-type']).toBe('application/x-protobuf');
108+
expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
109+
});
110+
111+
Object.keys(require.cache).forEach(key => {
112+
delete require.cache[key];
113+
});
114+
const requireStub = sandbox.stub(require('module'), '_load');
115+
requireStub.withArgs(dependency).throws(new Error(`Cannot find module '${dependency}'`));
116+
requireStub.callThrough();
117+
118+
await exporter.export([], () => {});
119+
});
132120
});
121+
});
133122

134-
const stubbedModule = proxyquire('../src/otlp-aws-span-exporter', {
135-
'@smithy/signature-v4': {
136-
SignatureV4: class MockSignatureV4 {
137-
sign() {
138-
throw new Error('signing error');
139-
}
140-
},
141-
},
142-
});
123+
// it('should not inject SigV4 headers if failure to sign headers', async () => {
124+
// scope.on('request', (req, interceptor, body) => {
125+
// const headers = req.headers;
126+
// expect(headers).not.toHaveProperty(AUTHORIZATION_HEADER);
127+
// expect(headers).not.toHaveProperty(X_AMZ_DATE_HEADER);
128+
// expect(headers).not.toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER);
129+
130+
// expect(headers['content-type']).toBe('application/x-protobuf');
131+
// expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
132+
// });
143133

144-
const exporter = new stubbedModule.OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT);
134+
// const stubbedModule = proxyquire('../src/otlp-aws-span-exporter', {
135+
// '@smithy/signature-v4': {
136+
// SignatureV4: class MockSignatureV4 {
137+
// sign() {
138+
// throw new Error('signing error');
139+
// }
140+
// },
141+
// },
142+
// });
145143

146-
await exporter.export([], () => {});
147-
});
144+
// const exporter = new stubbedModule.OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT);
148145

149-
it('should not inject SigV4 headers if failure to retrieve credentials', async () => {
150-
scope.on('request', (req, interceptor, body) => {
151-
const headers = req.headers;
152-
expect(headers).not.toHaveProperty(AUTHORIZATION_HEADER);
153-
expect(headers).not.toHaveProperty(X_AMZ_DATE_HEADER);
154-
expect(headers).not.toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER);
146+
// await exporter.export([], () => {});
147+
// });
155148

156-
expect(headers['content-type']).toBe('application/x-protobuf');
157-
expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
158-
});
149+
// it('should not inject SigV4 headers if failure to retrieve credentials', async () => {
150+
// scope.on('request', (req, interceptor, body) => {
151+
// const headers = req.headers;
152+
// expect(headers).not.toHaveProperty(AUTHORIZATION_HEADER);
153+
// expect(headers).not.toHaveProperty(X_AMZ_DATE_HEADER);
154+
// expect(headers).not.toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER);
159155

160-
const stubbedModule = proxyquire('../src/otlp-aws-span-exporter', {
161-
'@aws-sdk/credential-provider-node': {
162-
defaultProvider: () => async () => {
163-
throw new Error('credentials error');
164-
},
165-
},
166-
});
156+
// expect(headers['content-type']).toBe('application/x-protobuf');
157+
// expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
158+
// });
167159

168-
const exporter = new stubbedModule.OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT);
160+
// const stubbedModule = proxyquire('../src/otlp-aws-span-exporter', {
161+
// '@aws-sdk/credential-provider-node': {
162+
// defaultProvider: () => async () => {
163+
// throw new Error('credentials error');
164+
// },
165+
// },
166+
// });
169167

170-
await exporter.export([], () => {});
171-
});
168+
// const exporter = new stubbedModule.OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT);
169+
170+
// await exporter.export([], () => {});
171+
// });
172172
});
173173
}

contract-tests/tests/test/amazon/misc/resource_attributes_test_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ def assert_resource_attributes(self, service_name):
5757
)
5858
target_spans: List[Span] = []
5959
for resource_scope_span in resource_scope_spans:
60+
print("---" + resource_scope_span.span.name)
6061
# pylint: disable=no-member
61-
if resource_scope_span.span.name == "tcp.connect":
62+
if resource_scope_span.span.name == "GET /success":
6263
target_spans.append(resource_scope_span.resource_spans)
6364

6465
self.assertEqual(len(target_spans), 1)

0 commit comments

Comments
 (0)