|
1 | 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 | import expect from 'expect'; |
4 | | -// import { OTLPAwsSpanExporter } from '../src/otlp-aws-span-exporter'; |
| 4 | +import { OTLPAwsSpanExporter } from '../src/otlp-aws-span-exporter'; |
5 | 5 | import * as sinon from 'sinon'; |
6 | 6 | import * as proxyquire from 'proxyquire'; |
7 | 7 | import * as nock from 'nock'; |
@@ -66,108 +66,108 @@ if (nodeVersion >= 16) { |
66 | 66 | sandbox.restore(); |
67 | 67 | }); |
68 | 68 |
|
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); |
71 | 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()); |
| 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 | 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); |
| 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); |
81 | 81 |
|
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+$/); |
120 | 84 | // }); |
121 | | - // }); |
122 | 85 |
|
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 | + // }); |
129 | 88 |
|
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 | + }); |
132 | 120 | }); |
| 121 | + }); |
133 | 122 |
|
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 | + // }); |
143 | 133 |
|
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 | + // }); |
145 | 143 |
|
146 | | - await exporter.export([], () => {}); |
147 | | - }); |
| 144 | + // const exporter = new stubbedModule.OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT); |
148 | 145 |
|
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 | + // }); |
155 | 148 |
|
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); |
159 | 155 |
|
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 | + // }); |
167 | 159 |
|
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 | + // }); |
169 | 167 |
|
170 | | - await exporter.export([], () => {}); |
171 | | - }); |
| 168 | + // const exporter = new stubbedModule.OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT); |
| 169 | + |
| 170 | + // await exporter.export([], () => {}); |
| 171 | + // }); |
172 | 172 | }); |
173 | 173 | } |
0 commit comments