-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(oas-normalize): support for basic auth in url strings (#928)
| 🚥 Resolves readmeio/rdme#1152 | | :------------------- | ## 🧰 Changes When we moved `oas-normalize` off `node-fetch` and to native `fetch` we lost the ability to supply basic auth credentials directly in the URL string as `fetch` doesn't support that.
- Loading branch information
Showing
3 changed files
with
44 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,8 @@ describe('#load', () => { | |
['OpenAPI 3.0', '3.0'], | ||
['OpenAPI 3.1', '3.1'], | ||
])('%s support', (_, version) => { | ||
let json; | ||
let yaml; | ||
let json: Record<string, unknown>; | ||
let yaml: string; | ||
|
||
beforeEach(async () => { | ||
json = await import(`@readme/oas-examples/${version}/json/petstore.json`).then(r => r.default); | ||
|
@@ -67,6 +67,20 @@ describe('#load', () => { | |
await expect(o.load()).resolves.toStrictEqual(json); | ||
}); | ||
|
||
it('should support URLs with basic auth', async () => { | ||
nock('https://@example.com', { | ||
reqheaders: { | ||
Authorization: `Basic ${btoa('username:password')}`, | ||
}, | ||
}) | ||
.get(`/api-${version}.json`) | ||
.reply(200, json); | ||
|
||
const o = new OASNormalize(`https://username:[email protected]/api-${version}.json`); | ||
|
||
await expect(o.load()).resolves.toStrictEqual(json); | ||
}); | ||
|
||
it('should convert GitHub repo URLs to raw URLs', async () => { | ||
nock('https://raw.githubusercontent.com') | ||
.get('/readmeio/oas-examples/main/3.0/json/petstore.json') | ||
|