Skip to content

Commit 1e8ad24

Browse files
[Core AMQP] Do not stringify entityPath for undefined (Azure#12321)
Fixes Azure#8105 and Azure#11155
1 parent 3e56254 commit 1e8ad24

File tree

6 files changed

+59
-48
lines changed

6 files changed

+59
-48
lines changed

sdk/core/core-amqp/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## 2.0.0 (Unreleased)
44

5+
### Breaking Changes
6+
7+
- Previously, `ConnectionConfig.validate()` overridden entityPath if `undefined` with `String(undefined) = "undefined"`. This has been updated to retain `undefined` in the validation.
8+
[PR 12321](https://github.com/Azure/azure-sdk-for-js/pull/12321)
9+
510
## 2.0.0-beta.1 (2020-11-03)
611

712
- `AmqpAnnotatedMessage` interface that closely represents the AMQP annotated message from the [AMQP spec](https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#section-message-format) has been added. New `AmqpMessageHeaders` and `AmqpMessageProperties` interfaces(properties with camelCasing) have been added in the place of re-exports from "rhea" library(properties with snake_casing).

sdk/core/core-amqp/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
"lint": "eslint package.json api-extractor.json src test --ext .ts -f html -o core-amqp-lintReport.html || exit 0",
5252
"pack": "npm pack 2>&1",
5353
"prebuild": "npm run clean",
54-
"test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
55-
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
56-
"test": "npm run build:test && npm run unit-test && npm run integration-test",
54+
"test:browser": "npm run clean && npm run build:test && npm run unit-test:browser",
55+
"test:node": "npm run clean && npm run build:test && npm run unit-test:node",
56+
"test": "npm run test:node && npm run test:browser",
5757
"unit-test:browser": "karma start --single-run",
5858
"unit-test:node": "cross-env TS_NODE_FILES=true TS_NODE_COMPILER_OPTIONS=\"{\\\"module\\\":\\\"commonjs\\\"}\" nyc --reporter=lcov --reporter=text-lcov mocha -r ts-node/register -t 50000 --reporter ../../../common/tools/mocha-multi-reporter.js ./test/**/*.spec.ts",
5959
"unit-test": "npm run unit-test:node && npm run unit-test:browser"

sdk/core/core-amqp/src/connectionConfig/connectionConfig.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ export const ConnectionConfig = {
134134
if (options.isEntityPathRequired && !config.entityPath) {
135135
throw new TypeError("Missing 'entityPath' in configuration");
136136
}
137-
config.entityPath = String(config.entityPath);
137+
if (config.entityPath != undefined) {
138+
config.entityPath = String(config.entityPath);
139+
}
138140

139141
if (!isSharedAccessSignature(config.connectionString)) {
140142
if (!config.sharedAccessKeyName) {

sdk/core/core-amqp/test/config.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,46 @@ describe("ConnectionConfig", function() {
194194
done();
195195
});
196196
});
197+
198+
describe("EntityPath Validation", function() {
199+
const connectionString = `
200+
Endpoint=sb://hostname.servicebus.windows.net/;
201+
SharedAccessKeyName=sakName;
202+
SharedAccessKey=sakName;
203+
EntityPath=ep;
204+
`;
205+
const config: ConnectionConfig = {
206+
connectionString: connectionString,
207+
endpoint: "sb://hostname.servicebus.windows.net/",
208+
host: "hostname.servicebus.windows.net/",
209+
sharedAccessKeyName: "sakName",
210+
sharedAccessKey: "abcd"
211+
};
212+
213+
it("undefined is not stringified", () => {
214+
config.entityPath = undefined;
215+
ConnectionConfig.validate(config);
216+
should.equal(config.entityPath, undefined, `EntityPath is not undefined`);
217+
});
218+
219+
it("null is not stringified", () => {
220+
config.entityPath = null as any;
221+
ConnectionConfig.validate(config);
222+
should.equal(config.entityPath, null, `EntityPath is not null`);
223+
});
224+
225+
it("number is stringified", () => {
226+
config.entityPath = 3 as any;
227+
ConnectionConfig.validate(config);
228+
should.equal(config.entityPath, "3", `EntityPath is not stringified`);
229+
});
230+
231+
it("string is unchanged", () => {
232+
config.entityPath = "entityPath";
233+
ConnectionConfig.validate(config);
234+
should.equal(config.entityPath, "entityPath", `EntityPath is not a string`);
235+
});
236+
});
197237
});
198238

199239
describe("SharedAccessSignature", () => {

sdk/servicebus/service-bus/src/constructorHelpers.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,6 @@ export interface ServiceBusClientOptions {
2626
userAgentOptions?: UserAgentOptions;
2727
}
2828

29-
/**
30-
* @internal
31-
* @ignore
32-
*
33-
* @param {ConnectionConfig} config
34-
*/
35-
function validate(config: ConnectionConfig) {
36-
// TODO: workaround - core-amqp's validate string-izes "undefined"
37-
// the timing of this particular call happens in a spot where we might not have an
38-
// entity path so it's perfectly legitimate for it to be empty.
39-
config.entityPath = config.entityPath ?? "";
40-
41-
ConnectionConfig.validate(config);
42-
}
43-
4429
/**
4530
* @internal
4631
* @ignore
@@ -60,7 +45,6 @@ export function createConnectionContext(
6045
config.webSocketEndpointPath = "$servicebus/websocket";
6146
config.webSocketConstructorOptions = options?.webSocketOptions?.webSocketConstructorOptions;
6247

63-
validate(config);
6448
return ConnectionContext.create(config, credential, options);
6549
}
6650

sdk/servicebus/service-bus/test/internal/serviceBusClient.spec.ts

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ describe("serviceBusClient unit tests", () => {
5151

5252
client["_connectionContext"] = createConnectionContextForTestsWithSessionId(
5353
"a session id",
54-
origConnectionContext.config
54+
{
55+
...origConnectionContext.config,
56+
entityPath: testEntity.topic ? testEntity.topic : testEntity.queue
57+
}
5558
);
5659

5760
let sessionReceiver: ServiceBusSessionReceiver;
@@ -102,10 +105,10 @@ describe("serviceBusClient unit tests", () => {
102105

103106
const origConnectionContext = client["_connectionContext"];
104107

105-
client["_connectionContext"] = createConnectionContextForTestsWithSessionId(
106-
"session id",
107-
origConnectionContext.config
108-
);
108+
client["_connectionContext"] = createConnectionContextForTestsWithSessionId("session id", {
109+
...origConnectionContext.config,
110+
entityPath: testEntity.topic ? testEntity.topic : testEntity.queue
111+
});
109112

110113
let sessionReceiver: ServiceBusSessionReceiver;
111114

@@ -317,16 +320,6 @@ describe("serviceBusClient unit tests", () => {
317320
});
318321
validateWebsocketInfo(connectionContext, options);
319322
});
320-
321-
it("undefined entity path is translated to ''", () => {
322-
const connString = "Endpoint=sb://a;SharedAccessKeyName=b;SharedAccessKey=c;";
323-
const connectionContext = createConnectionContextForConnectionString(connString, {});
324-
assert.equal(
325-
connectionContext.config.entityPath,
326-
"",
327-
"Unexpected entityPath in the connection config"
328-
);
329-
});
330323
});
331324

332325
describe("createConnectionContextForTokenCredential", () => {
@@ -345,19 +338,6 @@ describe("serviceBusClient unit tests", () => {
345338
);
346339
validateWebsocketInfo(connectionContext, options);
347340
});
348-
349-
it("undefined entity path is translated to ''", () => {
350-
const connectionContext = createConnectionContextForTokenCredential(
351-
pseudoTokenCred,
352-
endpoint,
353-
{}
354-
);
355-
assert.equal(
356-
connectionContext.config.entityPath,
357-
"",
358-
"Unexpected entityPath in the connection config"
359-
);
360-
});
361341
});
362342
});
363343
});

0 commit comments

Comments
 (0)