-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add authentication for Libraries.io-based badges, run [Libraries Bowe…
…r] (#7080) * feat: support authentication on Libraries.io requests * feat: wire up libraries.io config and api provider instantiation * feat: create libraries.io and bower base classes * refactor: tweak libraries/bower service classes and tests * rename request fetcher function/arg * throw exception when no tokens available * cleanup old value Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
- Loading branch information
1 parent
6e100bf
commit ae58e4a
Showing
21 changed files
with
510 additions
and
81 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
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
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
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { expect } from 'chai' | ||
import { test, given } from 'sazerac' | ||
import nock from 'nock' | ||
import { cleanUpNockAfterEach, defaultContext } from '../test-helpers.js' | ||
import { InvalidResponse } from '../index.js' | ||
import LibrariesIoApiProvider from '../librariesio/librariesio-api-provider.js' | ||
import { BowerVersion } from './bower-version.service.js' | ||
|
||
describe('BowerVersion', function () { | ||
test(BowerVersion.transform, () => { | ||
given( | ||
{ | ||
latest_release_number: '2.0.0-beta', | ||
latest_stable_release_number: '1.8.3', | ||
}, | ||
false | ||
).expect('1.8.3') | ||
given( | ||
{ | ||
latest_release_number: '2.0.0-beta', | ||
latest_stable_release_number: '1.8.3', | ||
}, | ||
true | ||
).expect('2.0.0-beta') | ||
}) | ||
|
||
it('throws `no releases` InvalidResponse if no stable version', function () { | ||
expect(() => | ||
BowerVersion.transform({ latest_release_number: 'panda' }, false) | ||
) | ||
.to.throw(InvalidResponse) | ||
.with.property('prettyMessage', 'no releases') | ||
}) | ||
|
||
it('throws `no releases` InvalidResponse if no prereleases', function () { | ||
expect(() => | ||
BowerVersion.transform({ latest_stable_release_number: 'penguin' }, true) | ||
) | ||
.to.throw(InvalidResponse) | ||
.with.property('prettyMessage', 'no releases') | ||
}) | ||
|
||
context('auth', function () { | ||
cleanUpNockAfterEach() | ||
const fakeApiKey = 'fakeness' | ||
const response = { | ||
normalized_licenses: [], | ||
latest_release_number: '2.0.0-beta', | ||
latest_stable_release_number: '1.8.3', | ||
} | ||
const config = { | ||
private: { | ||
librariesio_tokens: fakeApiKey, | ||
}, | ||
} | ||
const librariesIoApiProvider = new LibrariesIoApiProvider({ | ||
baseUrl: 'https://libraries.io/api', | ||
tokens: [fakeApiKey], | ||
}) | ||
|
||
it('sends the auth information as configured', async function () { | ||
const scope = nock('https://libraries.io/api') | ||
// This ensures that the expected credentials are actually being sent with the HTTP request. | ||
// Without this the request wouldn't match and the test would fail. | ||
.get(`/bower/bootstrap?api_key=${fakeApiKey}`) | ||
.reply(200, response) | ||
|
||
expect( | ||
await BowerVersion.invoke( | ||
{ | ||
...defaultContext, | ||
librariesIoApiProvider, | ||
}, | ||
config, | ||
{ | ||
platform: 'bower', | ||
packageName: 'bootstrap', | ||
}, | ||
{ | ||
include_prereleases: '', | ||
} | ||
) | ||
).to.deep.equal({ | ||
message: 'v2.0.0-beta', | ||
color: 'orange', | ||
label: undefined, | ||
}) | ||
|
||
scope.done() | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.