Skip to content

Commit 230fd72

Browse files
Revert "[Recorder] Workaround for the "url-path with single quotes" bug in nock (Azure#13474)" (Azure#13488)
This reverts commit 5cd508c. Since the regex had replaced an expected fixture at data-tables PR. TODO: Come up with another regex that would not affect the single quotes in the second argument of `post()` call in the nock fixture.
1 parent cad2823 commit 230fd72

File tree

4 files changed

+3
-152
lines changed

4 files changed

+3
-152
lines changed

sdk/test-utils/recorder/CHANGELOG.md

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

33
## 1.0.0 (Unreleased)
44

5-
## 2020-01-28
6-
7-
- Single quotes can be present in the url path though unusual. When the url path has single quotes, the fixture generated by "nock" is incorrect leading to invalid recordings. [#13474](https://github.com/Azure/azure-sdk-for-js/pull/13474) introduces a workaround to be applied as part of the default customizations done on the generated recordings to fix the issue.
8-
95
## 2020-12-02
106

117
- Refactored the code to enable `"browser"` module replacement when used with bundlers. Previously, even browser bundled copies of the recorder would carry dependencies on several Node packages, which would lead to unresolved dependency warnings in Rollup regarding node builtins. With this change, the recorder's browser mappings will avoid this issue.

sdk/test-utils/recorder/src/baseRecorder.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import {
88
filterSecretsFromStrings,
99
filterSecretsRecursivelyFromJSON,
1010
generateTestRecordingFilePath,
11-
decodeHexEncodingIfExistsInNockFixture,
12-
handleSingleQuotesInUrlPath
11+
decodeHexEncodingIfExistsInNockFixture
1312
} from "./utils";
1413

1514
/**
@@ -42,10 +41,7 @@ export abstract class BaseRecorder {
4241
private defaultCustomizationsOnRecordings = !isBrowser()
4342
? [
4443
// Decodes "hex" strings in the response from the recorded fixture if any exists.
45-
decodeHexEncodingIfExistsInNockFixture,
46-
// Nock bug: Single quotes in the path of the url are not handled by nock.
47-
// The following is the workaround we use in the recorder until nock fixes it.
48-
handleSingleQuotesInUrlPath
44+
decodeHexEncodingIfExistsInNockFixture
4945
]
5046
: [];
5147

sdk/test-utils/recorder/src/utils/index.ts

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -389,48 +389,6 @@ export function decodeHexEncodingIfExistsInNockFixture(fixture: string): string
389389
return fixture;
390390
}
391391

392-
/**
393-
* Meant for node recordings only!
394-
*
395-
* Single quotes can be present in the url path though unusual.
396-
* When the url path has single quotes, the fixture generated by "nock" is incorrect
397-
* since it doesn't consider the case.
398-
* Examples below:
399-
* .delete('/Tables('node')')
400-
* .get('/Tables('node')')
401-
* .post('/Tables('node')', {"TableName":"testTablenode"})
402-
*
403-
* The above problem results in invalid recordings.
404-
*
405-
* To avoid this problem, we replace the single quotes surrounding the url-path in the recording
406-
* with backticks(`). This would fix the invalid recordings.
407-
*
408-
* @private
409-
* @param {string} fixture
410-
*/
411-
export function handleSingleQuotesInUrlPath(fixture: string): string {
412-
let updatedFixture = fixture;
413-
if (!isBrowser()) {
414-
// Fixtures would contain url-path as shown below
415-
// 1) .{method}('{url-path}')
416-
// 2) .{method}('{url-path}', {json-object})
417-
// Examples:
418-
// .get('/Tables('node')')
419-
// .post('/Tables('node')', {"TableName":"node"})
420-
const matches = fixture.match(/\.(get|put|post|delete)\(\'(.*)\'(\,|\))/);
421-
422-
if (matches && matches[2]) {
423-
const match = matches[2]; // Extracted url-path
424-
// If the url-path contains a single quote
425-
if (match.search("'") !== -1) {
426-
// Replace the occurrence of surrounding single quotes with backticks
427-
updatedFixture = fixture.replace("'" + match + "'", "`" + match + "`");
428-
}
429-
}
430-
}
431-
return updatedFixture;
432-
}
433-
434392
/**
435393
* List of binary content types.
436394
* Currently, "avro/binary" is the only one present.

sdk/test-utils/recorder/test/node/utils.spec.ts

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {
33
isBrowser,
44
testHasChanged,
55
isContentTypeInNockFixture,
6-
decodeHexEncodingIfExistsInNockFixture,
7-
handleSingleQuotesInUrlPath
6+
decodeHexEncodingIfExistsInNockFixture
87
} from "../../src/utils";
98

109
import { nodeRequireRecordingIfExists, findRecordingsFolderPath } from "../../src/utils/recordings";
@@ -395,102 +394,4 @@ describe("NodeJS utils", () => {
395394
});
396395
});
397396
});
398-
399-
describe("handleSingleQuotesInUrlPath", () => {
400-
[
401-
{
402-
name: `single quotes in get request in the fixture with request body`,
403-
input: `nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true})
404-
.get('/'path'', "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><QueryRequest><Expression>select * from BlobStorage</Expression></QueryRequest>")
405-
.query(true)
406-
.reply(200, "4f626a0131c2", [
407-
'Transfer-Encoding',
408-
'chunked'
409-
]);`,
410-
output: `nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true})
411-
.get(\`/'path'\`, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><QueryRequest><Expression>select * from BlobStorage</Expression></QueryRequest>")
412-
.query(true)
413-
.reply(200, "4f626a0131c2", [
414-
'Transfer-Encoding',
415-
'chunked'
416-
]);`
417-
},
418-
{
419-
name: `single quotes in get request in the fixture with no request body`,
420-
input: `nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true})
421-
.get('/'path'')
422-
.query(true)
423-
.reply(200, "4f626a0131c2", [
424-
'Transfer-Encoding',
425-
'chunked'
426-
]);`,
427-
output: `nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true})
428-
.get(\`/'path'\`)
429-
.query(true)
430-
.reply(200, "4f626a0131c2", [
431-
'Transfer-Encoding',
432-
'chunked'
433-
]);`
434-
},
435-
{
436-
name: `single quotes in delete request in the fixture with no request body`,
437-
input: `nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true})
438-
.delete('/'path'pathx')
439-
.query(true)
440-
.reply(200, "4f626a0131c2", [
441-
'Transfer-Encoding',
442-
'chunked'
443-
]);`,
444-
output: `nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true})
445-
.delete(\`/'path'pathx\`)
446-
.query(true)
447-
.reply(200, "4f626a0131c2", [
448-
'Transfer-Encoding',
449-
'chunked'
450-
]);`
451-
},
452-
{
453-
name: `no single quotes in get request in the fixture`,
454-
input: `nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true})
455-
.delete('/path')
456-
.query(true)
457-
.reply(200, "4f626a0131c2", [
458-
'Transfer-Encoding',
459-
'chunked'
460-
]);`,
461-
output: `nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true})
462-
.delete('/path')
463-
.query(true)
464-
.reply(200, "4f626a0131c2", [
465-
'Transfer-Encoding',
466-
'chunked'
467-
]);`
468-
},
469-
{
470-
name: `more than two single quotes in delete request in the fixture`,
471-
input: `nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true})
472-
.delete('/p'''a't'h')
473-
.query(true)
474-
.reply(200, "4f626a0131c2", [
475-
'Transfer-Encoding',
476-
'chunked'
477-
]);`,
478-
output: `nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true})
479-
.delete(\`/p'''a't'h\`)
480-
.query(true)
481-
.reply(200, "4f626a0131c2", [
482-
'Transfer-Encoding',
483-
'chunked'
484-
]);`
485-
}
486-
].forEach((test) => {
487-
it(test.name, () => {
488-
chai.assert.equal(
489-
handleSingleQuotesInUrlPath(test.input),
490-
test.output,
491-
`Output from "handleSingleQuotesInUrlPath" did not match the expected output`
492-
);
493-
});
494-
});
495-
});
496397
});

0 commit comments

Comments
 (0)