Skip to content

Commit 81c6152

Browse files
committed
test update contract test
1 parent 30831ae commit 81c6152

File tree

2 files changed

+91
-90
lines changed

2 files changed

+91
-90
lines changed
Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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';
66
import * as proxyquire from 'proxyquire';
77
import * as nock from 'nock';
@@ -66,108 +66,108 @@ if (nodeVersion >= 16) {
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);
69+
// it('Should inject SigV4 Headers successfully', async () => {
70+
// const exporter = new mockModule.OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT + XRAY_OTLP_ENDPOINT_PATH);
7171

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());
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());
7777

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);
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);
8181

82-
expect(headers['content-type']).toBe('application/x-protobuf');
83-
expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
84-
});
85-
86-
await exporter.export([], () => {});
87-
});
88-
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)