* improve stackexchange auth testing
Change auth tests to include all shields of the base class.
The code is formated to be used in more general cases and increases code reuseability.
* Remove dummy auth test
We already test all existing classes, no need for a dummy
* Add getBadgeExampleCall to test-helpers
Add getBadgeExampleCall to extract the first OpenAPI example then reformat it for service invoke function.
* Use getBadgeExampleCall in stackexchange-base tests
* Fix getBadgeExampleCall Errors
* Add testAuth to test-helpers
Add the testAuth function which tests auth of a service (badge) using a provided dummy response.
* Refactor stackexchange-base.spec.js to use testAuth from test-helpers
* Split stackexchange-base.spec into per service test file
* Add all auth methods to testAuth
Add all auth methods used to testAuth to be generic and used by all services.
Add helper functions to make testAuth more readable
* Handle non-default bearer and api headers
* Add discord.spec.js as first attempt for bearer auth
* Fix basic auth user
* Add dynamic authorizedOrigins
* Add header optional argument
* Add obs as basicAuth example
* Use apiHeaderKey and bearerHeaderKey function params
Use apiHeaderKey & bearerHeaderKey as function params rather then extracting them with regex from function strings.
Those options are now part of an options object param joined with the contentType that replaces header.
header was originaly added for setting content type of the reply, so it makes more sense to directly set the content type
* Remove old comment
* Allow any pass & user key for QueryStringAuth
Before this commit the QueryStringAuth would only work for the key of stackexchange.
This commit makes the testAuth function generic and allows passing user and pass keys.
* Add auth test for PepyDownloads
* Fix wrong header for jwt login
Might set wrong header for jwt login request.
This commit fixes that.
* Support multiple authOrigins in testAuth
Some services might have more then one authOrigin.
This commit makes sure we test for redundent authOrigins as well as support requests to them if needed.
* Add docker-automated auth test
* Fix JwtAuth testing by introducing mandatory jwtLoginEndpoint
Prior to this change, JwtAuth testing would lead to erros due to the absence of a specified login endpoint,
Nock would be dumplicated for both login and non login hosts and indicate a missing request.
This commit enforces the requirement for a new jwtLoginEndpoint argument when testing JwtAuth.
The argument seperates the endpoint nock scope from the behavior of the request nock.
* Fix type test in generateFakeConfig
* allow user to set dockerhub credentials
* add withJwtAuth function to AuthHelper
* use withJwtAuth in DockerHub badges
* add unit tests for JWT auth
* use auth when calling docker cloud
* refactor and assert fetch helpers call withJwtAuth
* store token for a max duration (defaults to 1 hour)
* tangent: update test example
* allow serviceData to override cacheSeconds with a longer value
* prevent [endpoint] json cacheSeconds property exceeding service default
* allow ShieldsRuntimeError to specify a cacheSeconds property
By default error responses use the cacheLength of
the service class throwing the error.
This allows error to tell the handling layer the maxAge
that should be set on the error badge response.
* add customExceptions param
This
1. allows us to specify custom properties to pass to the exception
constructor if we throw any of the standard got errors
e.g: `ETIMEDOUT`, `ECONNRESET`, etc
2. uses a custom `cacheSeconds` property (if set on the exception)
to set the response maxAge
* customExceptions --> systemErrors
* errorMessages --> httpErrors
* refactor: add render helper for downloads badges
* refactor: use new helper in some download badge classes
* doc renderer function
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
* [Docker] Support architecture query param in docker version badge
* [Docker] Add new unit test with architecture query param
* Run prettier
* [Docker] Add arch param in customizer example
* [Docker] version badge: Update test cases for arch param
* [Docker] Add arch param valid values
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
* fix: TypeError in DockerVersion badge
* A reference to the issue in test
Co-authored-by: Paul Melnikow <github@paulmelnikow.com>
Co-authored-by: Paul Melnikow <github@paulmelnikow.com>
* Add [Docker] image size badge
* Add [Docker] version/tag badge
* [Docker] allow version badge to retrieve results from multiple pages
* [Docker] allow size badge to retrieve results from multiple pages
* [Docker] clean up size and version badges before squash
* [Docker] Size badge change API call to explicit tag
* [Docker] Conditionally include tag route param for badges
* [Docker] Implement feedback for size and version badges
* [Docker] Implement feedback round 2 for size and version badges
* [Docker] Optimise API lookups and remove date sorting on tag badge
* [Docker] Implement feedback round 3 for version badge
* [Docker] Implement feedback round 4 for version badge
* [Docker] Adjust unit and service tests for version badge
* [Docker] Move unit test data into fixtures
* [Docker] Fix Docker version badge route prefix
* [Docker] Add date and semver lookup for size badge
* [Docker] Implement feedback round 5 for version badge
* [Docker] Implement feedback round 6
* [Docker] Tweak error messaging for consistent wording
* [Docker] Adjust badge titles
* [Docker] Guard and treat images with missing digest
* [Docker] Guard and treat images with missing digest
* Modernised JSON format and removed _shields_test style
* Added logoWidth and labelColor fields to JSON response
* Reinstated and updated comment
* Extended expectBadge to accept Joi schemas for all fields
This moves a few helpers from `lib/` to `services/`:
build-status.js
build-status.spec.js
color-formatters.js
color-formatters.spec.js
contributor-count.js
licenses.js
licenses.spec.js
php-version.js
php-version.spec.js
text-formatters.js
text-formatters.spec.js
version.js
version.spec.js
And one from `lib/` to `core/`:
unhandled-rejection.spec.js
The diff is long, but the changes are straightforward.
Ref #2832
This will definitely save time, and ensure more uniformity.
It moves the `createServiceTester()` calls to a different place from where I'd like them, though I'm happy to have them checked by the linter.
Closes#2701
Fixes#2876 with @paulmelnikow's suggestion
Moved imports of `ServiceTester` and `createServiceTester` to a separate file so that dev dependencies are not imported by service classes.
Continue to implement #2698:
- Add `core/base-service/index.js` (but hold off on moving the things it imports)
- Add shortcuts in `services/index.js` for Base*Service, errors, and deprecatedService. This file will be streamlined later to avoid cluttering it with rarely used bits.
- Apply consistent ordering of imports and use of `module.exports` in testers.
- Remove some renaming of imports.
- Remove obsolete tests here and there.
We had only a few function expressions declared with the function keyword; almost everything is using function declarations.
This came up after this discussion: https://github.com/badges/shields/pull/2803#discussion_r249011621 though is actually not related ot that example.
What’s being removed is a third option, which is assigning to a variable a function expression using the `function` keyword. There’s still room for the programmer to choose between arrow function expressions and function declarations.
- Replace the idea of color schemes with the idea of named colors (since none of our colorschemes have used `colorA`)
- Pass through the normalized color to `_shields_test` to harmonize with BaseService and simplify testing
- Update service tests
- Move responsibility for color generation into the npm package
- Remove several color helper functions and their tests
- Update gh-badge public API to accept `color` and `labelColor`
This is a precursor to refactoring some of the logo code for #2473.
Close#2334
To avoid merge conflicts, I've deferred removing the aliasing logic in `prepareExamples`. That whole function will be refactored momentarily, and there's also #2339 open.
The term “url” is overloaded in services, to refer to the Shields route and also the API URL. Calling the Shields URL a “route” is on the whole more descriptive, and makes it clearer and more obvious which one of these we’re talking about. It’s a small thing, though seems like an improvement.
We have a few functions called `buildUrl`. I’ve renamed them to `buildRoute` when they refer to routes, and left them as `buildUrl` when they refer to API URLs.
I included a minor style tweak and some formatting cleanup in `TUTORIAL.md`.
This is consistent with what we're pretty much already doing, and saves us from making the request during code review.
These were all autofixed and most of them seem easier to read. Some in the legacy services should be rewritten in more legible forms during refactor (ie using intermediate variables, or using request’s qs option). There are some in helper functions and elsewhere that should get rewritten separately. I don't want to change them in this PR because the changes will get lost in this diff, though we could identify them here and fix them before or just after.