@microsoft/applicationinsights-common 2.7.2-nightly.2111-05 → 2.7.2-nightly.2111-09
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Tests/Unit/src/AppInsightsCommon.tests.ts +291 -0
- package/Tests/Unit/src/ConnectionStringParser.tests.ts +126 -0
- package/Tests/Unit/src/Exception.tests.ts +88 -0
- package/Tests/Unit/src/Util.tests.ts +552 -0
- package/Tests/Unit/src/appinsights-common.tests.ts +11 -0
- package/Tests/UnitTests.html +48 -0
- package/Tests/tsconfig.json +13 -0
- package/api-extractor.json +360 -0
- package/applicationinsights-common.build.error.log +194 -0
- package/applicationinsights-common.build.log +745 -0
- package/browser/applicationinsights-common.integrity.json +9 -9
- package/browser/applicationinsights-common.js +1 -1
- package/browser/applicationinsights-common.js.map +1 -1
- package/browser/applicationinsights-common.min.js +1 -1
- package/browser/applicationinsights-common.min.js.map +1 -1
- package/dist/applicationinsights-common.api.json +1 -1
- package/dist/applicationinsights-common.d.ts +1 -1
- package/dist/applicationinsights-common.js +1 -1
- package/dist/applicationinsights-common.js.map +1 -1
- package/dist/applicationinsights-common.min.js +1 -1
- package/dist/applicationinsights-common.min.js.map +1 -1
- package/dist/applicationinsights-common.rollup.d.ts +1 -1
- package/dist-esm/ConnectionStringParser.js +1 -1
- package/dist-esm/Constants.js +1 -1
- package/dist-esm/DomHelperFuncs.js +1 -1
- package/dist-esm/Enums.js +1 -1
- package/dist-esm/HelperFuncs.js +1 -1
- package/dist-esm/Interfaces/ConnectionString.js +1 -1
- package/dist-esm/Interfaces/Context/IApplication.js +1 -1
- package/dist-esm/Interfaces/Context/IDevice.js +1 -1
- package/dist-esm/Interfaces/Context/IInternal.js +1 -1
- package/dist-esm/Interfaces/Context/ILocation.js +1 -1
- package/dist-esm/Interfaces/Context/IOperatingSystem.js +1 -1
- package/dist-esm/Interfaces/Context/ISample.js +1 -1
- package/dist-esm/Interfaces/Context/ISession.js +1 -1
- package/dist-esm/Interfaces/Context/ITelemetryTrace.js +1 -1
- package/dist-esm/Interfaces/Context/IUser.js +1 -1
- package/dist-esm/Interfaces/Context/IWeb.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/AvailabilityData.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/Base.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/ContextTagKeys.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/Data.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/DataPoint.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/DataPointType.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/DependencyKind.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/DependencySourceType.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/Domain.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/Envelope.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/EventData.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/ExceptionData.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/ExceptionDetails.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/MessageData.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/MetricData.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/PageViewData.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/PageViewPerfData.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/RemoteDependencyData.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/RequestData.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/SeverityLevel.js +1 -1
- package/dist-esm/Interfaces/Contracts/Generated/StackFrame.js +1 -1
- package/dist-esm/Interfaces/IAppInsights.js +1 -1
- package/dist-esm/Interfaces/IChannelControlsAI.js +1 -1
- package/dist-esm/Interfaces/IConfig.js +1 -1
- package/dist-esm/Interfaces/ICorrelationConfig.js +1 -1
- package/dist-esm/Interfaces/IDependencyTelemetry.js +1 -1
- package/dist-esm/Interfaces/IEventTelemetry.js +1 -1
- package/dist-esm/Interfaces/IExceptionTelemetry.js +1 -1
- package/dist-esm/Interfaces/IMetricTelemetry.js +1 -1
- package/dist-esm/Interfaces/IPageViewPerformanceTelemetry.js +1 -1
- package/dist-esm/Interfaces/IPageViewTelemetry.js +1 -1
- package/dist-esm/Interfaces/IPartC.js +1 -1
- package/dist-esm/Interfaces/IPropertiesPlugin.js +1 -1
- package/dist-esm/Interfaces/IRequestContext.js +1 -1
- package/dist-esm/Interfaces/ITelemetryContext.js +1 -1
- package/dist-esm/Interfaces/ITraceTelemetry.js +1 -1
- package/dist-esm/Interfaces/PartAExtensions.js +1 -1
- package/dist-esm/Interfaces/Telemetry/IEnvelope.js +1 -1
- package/dist-esm/Interfaces/Telemetry/ISerializable.js +1 -1
- package/dist-esm/RequestResponseHeaders.js +1 -1
- package/dist-esm/StorageHelperFuncs.js +1 -1
- package/dist-esm/Telemetry/Common/Base.js +1 -1
- package/dist-esm/Telemetry/Common/Data.js +1 -1
- package/dist-esm/Telemetry/Common/DataPoint.js +1 -1
- package/dist-esm/Telemetry/Common/DataSanitizer.js +1 -1
- package/dist-esm/Telemetry/Common/Envelope.js +1 -1
- package/dist-esm/Telemetry/Event.js +1 -1
- package/dist-esm/Telemetry/Exception.js +1 -1
- package/dist-esm/Telemetry/Metric.js +1 -1
- package/dist-esm/Telemetry/PageView.js +1 -1
- package/dist-esm/Telemetry/PageViewPerformance.js +1 -1
- package/dist-esm/Telemetry/RemoteDependencyData.js +1 -1
- package/dist-esm/Telemetry/Trace.js +1 -1
- package/dist-esm/TelemetryItemCreator.js +1 -1
- package/dist-esm/UrlHelperFuncs.js +1 -1
- package/dist-esm/Util.js +1 -1
- package/dist-esm/applicationinsights-common.js +1 -1
- package/microsoft-applicationinsights-common-2.7.2-nightly.2111-09.tgz +0 -0
- package/package.json +2 -2
- package/rollup.config.js +139 -0
- package/temp/applicationinsights-common.api.md +1140 -0
- package/tslint.json +11 -0
- package/types/tsdoc-metadata.json +1 -1
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { Assert, AITestClass } from "@microsoft/ai-test-framework";
|
|
2
|
+
import {
|
|
3
|
+
ITelemetryItem, AppInsightsCore,
|
|
4
|
+
IPlugin, IConfiguration, DiagnosticLogger
|
|
5
|
+
} from "@microsoft/applicationinsights-core-js";
|
|
6
|
+
|
|
7
|
+
import { DataSanitizer } from "../../../src/Telemetry/Common/DataSanitizer";
|
|
8
|
+
|
|
9
|
+
export class ApplicationInsightsTests extends AITestClass {
|
|
10
|
+
logger = new DiagnosticLogger();
|
|
11
|
+
|
|
12
|
+
public testInitialize() {
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public testCleanup() {
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public registerTests() {
|
|
19
|
+
// test cases for sanitizeMessage function
|
|
20
|
+
this.testCase({
|
|
21
|
+
name: 'DataSanitizerTests: messages are well processed.',
|
|
22
|
+
test: () => {
|
|
23
|
+
// const define
|
|
24
|
+
const MAX_MESSAGE_LENGTH = DataSanitizer.MAX_MESSAGE_LENGTH;
|
|
25
|
+
|
|
26
|
+
// use cases
|
|
27
|
+
const messageShort: String = "hi";
|
|
28
|
+
const messageLong = new Array(MAX_MESSAGE_LENGTH + 1).join('abc');
|
|
29
|
+
|
|
30
|
+
// Assert
|
|
31
|
+
Assert.equal(messageShort.length, DataSanitizer.sanitizeMessage(this.logger, messageShort).length);
|
|
32
|
+
Assert.notEqual(messageLong.length, DataSanitizer.sanitizeMessage(this.logger, messageLong).length);
|
|
33
|
+
Assert.equal(MAX_MESSAGE_LENGTH, DataSanitizer.sanitizeMessage(this.logger, messageLong).length);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
this.testCase({
|
|
38
|
+
name: 'DataSanitizerTests: throwInternal function is called correctly in sanitizeMessage function',
|
|
39
|
+
test: () => {
|
|
40
|
+
// const define
|
|
41
|
+
const loggerStub = this.sandbox.stub(this.logger , "throwInternal");
|
|
42
|
+
const MAX_MESSAGE_LENGTH = DataSanitizer.MAX_MESSAGE_LENGTH;
|
|
43
|
+
|
|
44
|
+
// use cases
|
|
45
|
+
const messageShort: String = "hi";
|
|
46
|
+
const messageLong = new Array(MAX_MESSAGE_LENGTH + 2).join('a');
|
|
47
|
+
|
|
48
|
+
// Act
|
|
49
|
+
DataSanitizer.sanitizeMessage(this.logger, messageShort);
|
|
50
|
+
Assert.ok(loggerStub.notCalled);
|
|
51
|
+
Assert.equal(0, loggerStub.callCount);
|
|
52
|
+
|
|
53
|
+
DataSanitizer.sanitizeMessage(this.logger, messageLong);
|
|
54
|
+
Assert.ok(loggerStub.calledOnce);
|
|
55
|
+
Assert.equal(1, loggerStub.callCount);
|
|
56
|
+
|
|
57
|
+
DataSanitizer.sanitizeMessage(this.logger, messageLong);
|
|
58
|
+
Assert.ok(loggerStub.calledTwice);
|
|
59
|
+
Assert.equal(2, loggerStub.callCount);
|
|
60
|
+
|
|
61
|
+
loggerStub.restore();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
this.testCase({
|
|
66
|
+
name: 'DataSanitizerTests: messages are fully logged through console',
|
|
67
|
+
test: () => {
|
|
68
|
+
const saniMsgSpy = this.sandbox.spy(DataSanitizer, "sanitizeMessage");
|
|
69
|
+
|
|
70
|
+
// const define
|
|
71
|
+
const MAX_MESSAGE_LENGTH = DataSanitizer.MAX_MESSAGE_LENGTH;
|
|
72
|
+
|
|
73
|
+
// use cases
|
|
74
|
+
const messageShort: String = "hi";
|
|
75
|
+
const messageLong = new Array(MAX_MESSAGE_LENGTH + 1).join('a');
|
|
76
|
+
|
|
77
|
+
const msgShortResult = DataSanitizer.sanitizeMessage(this.logger, messageShort);
|
|
78
|
+
Assert.ok(saniMsgSpy.returned(msgShortResult));
|
|
79
|
+
|
|
80
|
+
const msgLongResult = DataSanitizer.sanitizeMessage(this.logger, messageLong);
|
|
81
|
+
Assert.ok(saniMsgSpy.returned(msgLongResult));
|
|
82
|
+
|
|
83
|
+
saniMsgSpy.restore();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// test cases for sanitizeString function
|
|
88
|
+
this.testCase({
|
|
89
|
+
name: 'DataSanitizerTest: strings are well processed',
|
|
90
|
+
test: () => {
|
|
91
|
+
// const define
|
|
92
|
+
const MAX_STRING_LENGTH = DataSanitizer.MAX_STRING_LENGTH;
|
|
93
|
+
|
|
94
|
+
// use cases
|
|
95
|
+
const strShort: String = "hi";
|
|
96
|
+
const strLong = new Array(MAX_STRING_LENGTH + 2).join('a');
|
|
97
|
+
|
|
98
|
+
// Assert
|
|
99
|
+
Assert.equal(strShort.length, DataSanitizer.sanitizeString(this.logger, strShort).length);
|
|
100
|
+
Assert.notEqual(strLong.length, DataSanitizer.sanitizeString(this.logger, strLong).length);
|
|
101
|
+
Assert.equal(MAX_STRING_LENGTH, DataSanitizer.sanitizeString(this.logger, strLong).length);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
this.testCase({
|
|
106
|
+
name: 'DataSanitizerTests: throrwInternal function is called correctly in sanitizeString function',
|
|
107
|
+
test: () => {
|
|
108
|
+
// const define
|
|
109
|
+
const loggerStub = this.sandbox.stub(this.logger , "throwInternal");
|
|
110
|
+
const MAX_STRING_LENGTH = DataSanitizer.MAX_STRING_LENGTH;
|
|
111
|
+
|
|
112
|
+
// use cases
|
|
113
|
+
const strShort: String = "hi";
|
|
114
|
+
const strLong = new Array(MAX_STRING_LENGTH + 2).join('a');
|
|
115
|
+
|
|
116
|
+
// Act
|
|
117
|
+
DataSanitizer.sanitizeString(this.logger, strShort);
|
|
118
|
+
Assert.ok(loggerStub.notCalled);
|
|
119
|
+
Assert.equal(0, loggerStub.callCount);
|
|
120
|
+
|
|
121
|
+
DataSanitizer.sanitizeString(this.logger, strLong);
|
|
122
|
+
Assert.ok(loggerStub.calledOnce);
|
|
123
|
+
Assert.equal(1, loggerStub.callCount);
|
|
124
|
+
|
|
125
|
+
DataSanitizer.sanitizeString(this.logger, strLong);
|
|
126
|
+
Assert.ok(loggerStub.calledTwice);
|
|
127
|
+
Assert.equal(2, loggerStub.callCount);
|
|
128
|
+
|
|
129
|
+
loggerStub.restore();
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
this.testCase({
|
|
134
|
+
name: 'DataSanitizerTests: strings are fully logged through console',
|
|
135
|
+
test: () => {
|
|
136
|
+
const saniStrSpy = this.sandbox.spy(DataSanitizer, "sanitizeString");
|
|
137
|
+
|
|
138
|
+
// const define
|
|
139
|
+
const MAX_STRING_LENGTH = DataSanitizer.MAX_STRING_LENGTH;
|
|
140
|
+
|
|
141
|
+
// use cases
|
|
142
|
+
const strShort: String = "hi";
|
|
143
|
+
const strLong = new Array(MAX_STRING_LENGTH + 2).join('a');
|
|
144
|
+
|
|
145
|
+
const strShortResult = DataSanitizer.sanitizeString(this.logger, strShort);
|
|
146
|
+
Assert.ok(saniStrSpy.returned(strShortResult));
|
|
147
|
+
|
|
148
|
+
const strLongResult = DataSanitizer.sanitizeString(this.logger, strLong);
|
|
149
|
+
Assert.ok(saniStrSpy.returned(strLongResult));
|
|
150
|
+
|
|
151
|
+
saniStrSpy.restore();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// test cases for sanitizeKey function
|
|
156
|
+
this.testCase({
|
|
157
|
+
name: 'DataSanitizerTest: names are well processed',
|
|
158
|
+
test: () => {
|
|
159
|
+
// const define
|
|
160
|
+
const MAX_NAME_LENGTH = DataSanitizer.MAX_NAME_LENGTH;
|
|
161
|
+
|
|
162
|
+
// use cases
|
|
163
|
+
const nameShort: String = "hi";
|
|
164
|
+
const nameLong = new Array(MAX_NAME_LENGTH + 2).join('a');
|
|
165
|
+
|
|
166
|
+
// Assert
|
|
167
|
+
Assert.equal(nameShort.length, DataSanitizer.sanitizeKey(this.logger, nameShort).length);
|
|
168
|
+
Assert.notEqual(nameLong.length, DataSanitizer.sanitizeKey(this.logger, nameLong).length);
|
|
169
|
+
Assert.equal(MAX_NAME_LENGTH, DataSanitizer.sanitizeKey(this.logger, nameLong).length);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
this.testCase({
|
|
174
|
+
name: 'DataSanitizerTests: throrwInternal function is called correctly in sanitizeKey function',
|
|
175
|
+
test: () => {
|
|
176
|
+
// const define
|
|
177
|
+
const loggerStub = this.sandbox.stub(this.logger , "throwInternal");
|
|
178
|
+
const MAX_NAME_LENGTH = DataSanitizer.MAX_NAME_LENGTH;
|
|
179
|
+
|
|
180
|
+
// use cases
|
|
181
|
+
const nameShort: String = "hi";
|
|
182
|
+
const nameLong = new Array(MAX_NAME_LENGTH + 2).join('a');
|
|
183
|
+
|
|
184
|
+
// Act
|
|
185
|
+
DataSanitizer.sanitizeKey(this.logger, nameShort);
|
|
186
|
+
Assert.ok(loggerStub.notCalled);
|
|
187
|
+
Assert.equal(0, loggerStub.callCount);
|
|
188
|
+
|
|
189
|
+
DataSanitizer.sanitizeKey(this.logger, nameLong);
|
|
190
|
+
Assert.ok(loggerStub.calledOnce);
|
|
191
|
+
Assert.equal(1, loggerStub.callCount);
|
|
192
|
+
|
|
193
|
+
DataSanitizer.sanitizeKey(this.logger, nameLong);
|
|
194
|
+
Assert.ok(loggerStub.calledTwice);
|
|
195
|
+
Assert.equal(2, loggerStub.callCount);
|
|
196
|
+
|
|
197
|
+
loggerStub.restore();
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
this.testCase({
|
|
202
|
+
name: 'DataSanitizerTests: names are fully logged through console',
|
|
203
|
+
test: () => {
|
|
204
|
+
const saniStrSpy = this.sandbox.spy(DataSanitizer, "sanitizeKey");
|
|
205
|
+
|
|
206
|
+
// const define
|
|
207
|
+
const MAX_NAME_LENGTH = DataSanitizer.MAX_NAME_LENGTH;
|
|
208
|
+
|
|
209
|
+
// use cases
|
|
210
|
+
const nameShort: String = "hi";
|
|
211
|
+
const nameLong = new Array(MAX_NAME_LENGTH + 2).join('a');
|
|
212
|
+
|
|
213
|
+
const nameShortResult = DataSanitizer.sanitizeKey(this.logger, nameShort);
|
|
214
|
+
Assert.ok(saniStrSpy.returned(nameShortResult));
|
|
215
|
+
|
|
216
|
+
const nameLongResult = DataSanitizer.sanitizeKey(this.logger, nameLong);
|
|
217
|
+
Assert.ok(saniStrSpy.returned(nameLongResult));
|
|
218
|
+
|
|
219
|
+
saniStrSpy.restore();
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// test cases for sanitizeInput function
|
|
224
|
+
this.testCase({
|
|
225
|
+
name: 'DataSanitizerTest: inputs are well processed',
|
|
226
|
+
test: () => {
|
|
227
|
+
const MAX_INPUT_LENGTH = 1024;
|
|
228
|
+
|
|
229
|
+
// use cases
|
|
230
|
+
const inputShort: String = "hi";
|
|
231
|
+
const inputLong = new Array(MAX_INPUT_LENGTH + 2).join('a');
|
|
232
|
+
|
|
233
|
+
// Assert
|
|
234
|
+
Assert.equal(inputShort.length, DataSanitizer.sanitizeInput(this.logger, inputShort, MAX_INPUT_LENGTH, 0).length);
|
|
235
|
+
Assert.notEqual(inputLong.length, DataSanitizer.sanitizeInput(this.logger, inputLong, MAX_INPUT_LENGTH, 0).length);
|
|
236
|
+
Assert.equal(MAX_INPUT_LENGTH, DataSanitizer.sanitizeInput(this.logger, inputLong, MAX_INPUT_LENGTH, 0).length);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
this.testCase({
|
|
241
|
+
name: 'DataSanitizerTests: throrwInternal function is called correctly in sanitizeInput function',
|
|
242
|
+
test: () => {
|
|
243
|
+
// const define
|
|
244
|
+
const loggerStub = this.sandbox.stub(this.logger , "throwInternal");
|
|
245
|
+
const MAX_INPUT_LENGTH = 1024;
|
|
246
|
+
|
|
247
|
+
// use cases
|
|
248
|
+
const inputShort: String = "hi";
|
|
249
|
+
const inputLong = new Array(MAX_INPUT_LENGTH + 2).join('a');
|
|
250
|
+
|
|
251
|
+
// Act
|
|
252
|
+
DataSanitizer.sanitizeInput(this.logger, inputShort, MAX_INPUT_LENGTH, 0);
|
|
253
|
+
Assert.ok(loggerStub.notCalled);
|
|
254
|
+
Assert.equal(0, loggerStub.callCount);
|
|
255
|
+
|
|
256
|
+
DataSanitizer.sanitizeInput(this.logger, inputLong, MAX_INPUT_LENGTH, 0);
|
|
257
|
+
Assert.ok(loggerStub.calledOnce);
|
|
258
|
+
Assert.equal(1, loggerStub.callCount);
|
|
259
|
+
|
|
260
|
+
DataSanitizer.sanitizeInput(this.logger, inputLong, MAX_INPUT_LENGTH, 0);
|
|
261
|
+
Assert.ok(loggerStub.calledTwice);
|
|
262
|
+
Assert.equal(2, loggerStub.callCount);
|
|
263
|
+
|
|
264
|
+
loggerStub.restore();
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
this.testCase({
|
|
269
|
+
name: 'DataSanitizerTests: inputs are fully logged through console',
|
|
270
|
+
test: () => {
|
|
271
|
+
const saniStrSpy = this.sandbox.spy(DataSanitizer, "sanitizeInput");
|
|
272
|
+
|
|
273
|
+
// const define
|
|
274
|
+
const MAX_INPUT_LENGTH = 1024;
|
|
275
|
+
|
|
276
|
+
// use cases
|
|
277
|
+
const inputShort: String = "hi";
|
|
278
|
+
const inputLong = new Array(MAX_INPUT_LENGTH + 2).join('a');
|
|
279
|
+
|
|
280
|
+
const inputShortResult = DataSanitizer.sanitizeInput(this.logger, inputShort, MAX_INPUT_LENGTH, 0);
|
|
281
|
+
Assert.ok(saniStrSpy.returned(inputShortResult));
|
|
282
|
+
|
|
283
|
+
const inputLongResult = DataSanitizer.sanitizeInput(this.logger, inputLong, MAX_INPUT_LENGTH, 0);
|
|
284
|
+
Assert.ok(saniStrSpy.returned(inputLongResult));
|
|
285
|
+
|
|
286
|
+
saniStrSpy.restore();
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Assert, AITestClass } from "@microsoft/ai-test-framework";
|
|
2
|
+
import { ConnectionStringParser } from "../../../src/ConnectionStringParser";
|
|
3
|
+
import * as Constants from "../../../src/Constants";
|
|
4
|
+
|
|
5
|
+
const runTest = (options: {
|
|
6
|
+
connectionString: string,
|
|
7
|
+
expectedAuthorization?: string,
|
|
8
|
+
expectedInstrumentationKey?: string,
|
|
9
|
+
expectedBreezeEndpoint: string,
|
|
10
|
+
}) => {
|
|
11
|
+
const result = ConnectionStringParser.parse(options.connectionString);
|
|
12
|
+
|
|
13
|
+
if (options.expectedAuthorization) {
|
|
14
|
+
Assert.deepEqual(result.authorization, options.expectedAuthorization);
|
|
15
|
+
}
|
|
16
|
+
if (options.expectedInstrumentationKey) {
|
|
17
|
+
Assert.deepEqual(result.instrumentationkey, options.expectedInstrumentationKey);
|
|
18
|
+
}
|
|
19
|
+
Assert.deepEqual(result.ingestionendpoint, options.expectedBreezeEndpoint);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class ConnectionStringParserTests extends AITestClass {
|
|
23
|
+
|
|
24
|
+
public testInitialize() {
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public testCleanup() {}
|
|
28
|
+
|
|
29
|
+
public registerTests() {
|
|
30
|
+
this.testCase({
|
|
31
|
+
name: "should parse all valid fields",
|
|
32
|
+
test: () => {
|
|
33
|
+
const authorization = "ikey"
|
|
34
|
+
const instrumentationKey = "instr_key";
|
|
35
|
+
const ingestionEndpoint = "ingest";
|
|
36
|
+
const liveEndpoint = "live";
|
|
37
|
+
const connectionString = `Authorization=${authorization};InstrumentationKey=${instrumentationKey};IngestionEndpoint=${ingestionEndpoint};LiveEndpoint=${liveEndpoint}`;
|
|
38
|
+
|
|
39
|
+
const result = ConnectionStringParser.parse(connectionString);
|
|
40
|
+
|
|
41
|
+
Assert.deepEqual(result.authorization, authorization);
|
|
42
|
+
Assert.deepEqual(result.instrumentationkey, instrumentationKey);
|
|
43
|
+
Assert.deepEqual(result.ingestionendpoint, ingestionEndpoint);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
this.testCase({
|
|
48
|
+
name: "should ignore invalid fields",
|
|
49
|
+
test: () => {
|
|
50
|
+
const authorization = "ikey"
|
|
51
|
+
const instrumentationKey = "ikey";
|
|
52
|
+
const ingestionEndpoint = "ingest";
|
|
53
|
+
const liveEndpoint = "live";
|
|
54
|
+
const connectionString = `Autho.rization=${authorization};Instrume.ntationKey=${instrumentationKey};Ingestion.Endpoint=${ingestionEndpoint};LiveEnd.point=${liveEndpoint}`;
|
|
55
|
+
|
|
56
|
+
const result = ConnectionStringParser.parse(connectionString);
|
|
57
|
+
|
|
58
|
+
Assert.deepEqual(result.authorization, undefined);
|
|
59
|
+
Assert.deepEqual(result.instrumentationkey, undefined);
|
|
60
|
+
Assert.deepEqual(result.ingestionendpoint, Constants.DEFAULT_BREEZE_ENDPOINT);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
this.testCase({
|
|
65
|
+
name: "should use correct default endpoints",
|
|
66
|
+
test: () => {
|
|
67
|
+
runTest({
|
|
68
|
+
connectionString: "InstrumentationKey=00000000-0000-0000-0000-000000000000",
|
|
69
|
+
expectedAuthorization: undefined,
|
|
70
|
+
expectedInstrumentationKey: "00000000-0000-0000-0000-000000000000",
|
|
71
|
+
expectedBreezeEndpoint: Constants.DEFAULT_BREEZE_ENDPOINT,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
this.testCase({
|
|
77
|
+
name: "should use correct endpoints when using EndpointSuffix",
|
|
78
|
+
test: () => {
|
|
79
|
+
runTest({
|
|
80
|
+
connectionString: "InstrumentationKey=00000000-0000-0000-0000-000000000000;EndpointSuffix=ai.contoso.com",
|
|
81
|
+
expectedBreezeEndpoint: "https://dc.ai.contoso.com",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
this.testCase({
|
|
87
|
+
name: "should use correct endpoints when using EndpointSuffix with explicit override",
|
|
88
|
+
test: () => {
|
|
89
|
+
runTest({
|
|
90
|
+
connectionString: "InstrumentationKey=00000000-0000-0000-0000-000000000000;EndpointSuffix=ai.contoso.com;LiveEndpoint=https://custom.live.contoso.com:444",
|
|
91
|
+
expectedBreezeEndpoint: "https://dc.ai.contoso.com",
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
this.testCase({
|
|
97
|
+
name: "should parse EndpointSuffix + Location",
|
|
98
|
+
test: () => {
|
|
99
|
+
runTest({
|
|
100
|
+
connectionString: "InstrumentationKey=00000000-0000-0000-0000-000000000000;EndpointSuffix=ai.contoso.com;Location=westus2",
|
|
101
|
+
expectedBreezeEndpoint: "https://westus2.dc.ai.contoso.com",
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
this.testCase({
|
|
107
|
+
name: "should parse EndpointSuffix + Location + Endpoint Override",
|
|
108
|
+
test: () => {
|
|
109
|
+
runTest({
|
|
110
|
+
connectionString: "InstrumentationKey=00000000-0000-0000-0000-000000000000;EndpointSuffix=ai.contoso.com;Location=westus2;LiveEndpoint=https://custom.contoso.com:444",
|
|
111
|
+
expectedBreezeEndpoint: "https://westus2.dc.ai.contoso.com",
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
this.testCase({
|
|
117
|
+
name: "should parse Endpoint Override",
|
|
118
|
+
test: () => {
|
|
119
|
+
runTest({
|
|
120
|
+
connectionString: "InstrumentationKey=00000000-0000-0000-0000-000000000000;LiveEndpoint=http://custom.live.endpoint.com:444",
|
|
121
|
+
expectedBreezeEndpoint: Constants.DEFAULT_BREEZE_ENDPOINT,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Assert, AITestClass } from "@microsoft/ai-test-framework";
|
|
2
|
+
import { Exception } from "../../../src/applicationinsights-common"
|
|
3
|
+
import { DiagnosticLogger } from "@microsoft/applicationinsights-core-js";
|
|
4
|
+
import { IExceptionInternal, IExceptionDetailsInternal, IExceptionStackFrameInternal } from "../../../src/Interfaces/IExceptionTelemetry";
|
|
5
|
+
import { _ExceptionDetails, _StackFrame } from "../../../src/Telemetry/Exception";
|
|
6
|
+
|
|
7
|
+
export class ExceptionTests extends AITestClass {
|
|
8
|
+
logger = new DiagnosticLogger();
|
|
9
|
+
|
|
10
|
+
public testInitialize() {
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public testCleanup() {}
|
|
14
|
+
|
|
15
|
+
public registerTests() {
|
|
16
|
+
this.testCase({
|
|
17
|
+
name: "Exception: Exception can be exported to interface format",
|
|
18
|
+
test: () => {
|
|
19
|
+
const exception = new Exception(this.logger, new Error("test error"));
|
|
20
|
+
Assert.ok(exception, "Exception is created");
|
|
21
|
+
|
|
22
|
+
const exceptionInterface: IExceptionInternal = exception.toInterface();
|
|
23
|
+
Assert.deepEqual(exception.id, exceptionInterface.id);
|
|
24
|
+
Assert.deepEqual(exception.problemGroup, exceptionInterface.problemGroup);
|
|
25
|
+
Assert.deepEqual("4.0", exceptionInterface.ver, "Default format expects CS4.0");
|
|
26
|
+
Assert.deepEqual(2, exception.ver, "Breeze format expects CS2.0");
|
|
27
|
+
Assert.deepEqual(exception.isManual, exceptionInterface.isManual);
|
|
28
|
+
Assert.deepEqual(exception.exceptions.map((exception: any) => exception.toInterface()), exceptionInterface.exceptions);
|
|
29
|
+
Assert.deepEqual(exception.severityLevel, exceptionInterface.severityLevel);
|
|
30
|
+
Assert.deepEqual(exception.properties, exceptionInterface.properties);
|
|
31
|
+
Assert.deepEqual(exception.measurements, exceptionInterface.measurements);
|
|
32
|
+
|
|
33
|
+
const exceptionConverted = Exception.CreateFromInterface(this.logger, exceptionInterface);
|
|
34
|
+
Assert.deepEqual(exception, exceptionConverted);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
this.testCase({
|
|
39
|
+
name: "ExceptionDetails: ExceptionDetails can be exported to interface format",
|
|
40
|
+
test: () => {
|
|
41
|
+
try {
|
|
42
|
+
const exceptionDetails = new _ExceptionDetails(this.logger, new Error("test error"));
|
|
43
|
+
Assert.ok(exceptionDetails, "ExceptionDetails instance is created");
|
|
44
|
+
|
|
45
|
+
const exceptionDetailsInterface: IExceptionDetailsInternal = exceptionDetails.toInterface();
|
|
46
|
+
Assert.deepEqual(exceptionDetails.id, exceptionDetailsInterface.id);
|
|
47
|
+
Assert.deepEqual(exceptionDetails.outerId, exceptionDetailsInterface.outerId);
|
|
48
|
+
Assert.deepEqual(exceptionDetails.typeName, exceptionDetailsInterface.typeName);
|
|
49
|
+
Assert.deepEqual(exceptionDetails.message, exceptionDetailsInterface.message);
|
|
50
|
+
Assert.deepEqual(exceptionDetails.hasFullStack, exceptionDetailsInterface.hasFullStack);
|
|
51
|
+
Assert.deepEqual(exceptionDetails.stack, exceptionDetailsInterface.stack);
|
|
52
|
+
Assert.deepEqual(exceptionDetails.parsedStack && exceptionDetails.parsedStack.map((frame: _StackFrame) => frame.toInterface()), exceptionDetailsInterface.parsedStack);
|
|
53
|
+
|
|
54
|
+
const exceptionDetailsConverted = _ExceptionDetails.CreateFromInterface(this.logger, exceptionDetailsInterface);
|
|
55
|
+
Assert.deepEqual(exceptionDetails, exceptionDetailsConverted);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.log(e.stack);
|
|
58
|
+
console.log(e.toString());
|
|
59
|
+
Assert.ok(false, e.toString());
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
this.testCase({
|
|
65
|
+
name: "StackFrame: StackFrame can be exported to interface format",
|
|
66
|
+
test: () => {
|
|
67
|
+
const error = new Error("hello");
|
|
68
|
+
const stack = error.stack;
|
|
69
|
+
if (!stack) {
|
|
70
|
+
Assert.ok(true);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const stackFrame = new _StackFrame(stack.split("\n")[0], 0);
|
|
74
|
+
Assert.ok(stackFrame, "StackFrame instance is created");
|
|
75
|
+
|
|
76
|
+
const stackFrameInterface: IExceptionStackFrameInternal = stackFrame.toInterface();
|
|
77
|
+
Assert.deepEqual(stackFrame.level, stackFrameInterface.level);
|
|
78
|
+
Assert.deepEqual(stackFrame.method, stackFrameInterface.method);
|
|
79
|
+
Assert.deepEqual(stackFrame.assembly, stackFrameInterface.assembly);
|
|
80
|
+
Assert.deepEqual(stackFrame.fileName, stackFrameInterface.fileName);
|
|
81
|
+
Assert.deepEqual(stackFrame.line, stackFrameInterface.line);
|
|
82
|
+
|
|
83
|
+
// var stackFrameConverted = _StackFrame.CreateFromInterface(stackFrameInterface);
|
|
84
|
+
// Assert.deepEqual(stackFrame, stackFrameConverted);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|