* [AzureDevops] Authenticate build badge via REST API (#10162)
* [AzureDevops] Restore stage/job parity for build badge via Timeline API (#10162)
* Align build badge not-found message with sibling Azure badges
Use 'build pipeline not found' (matching AzureDevOpsCoverage/Tests)
instead of 'user or project not found', and treat a pipeline with no
completed builds the same way. Replace the mocked 404 test with live
not-found tests, following the sibling testers' approach.
* refactor: rename deprecatedService to retiredService
- Updated all instances of deprecatedService to retiredService in service implementations, tests, and documentation.
- Changed attribute names from isDeprecated to isRetired in relevant schemas and service definitions.
- Adjusted tests and documentation to reflect the new terminology and ensure consistency.
* docs: rename deprecating-badges.md to retiring-badges.md
* refactor: rename files deprecated-service to retired-service
* refactor: update terminology from deprecated to retired in badge documentation
* 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
* Add exampleOverride to testAuth
Introduce `exampleOverride` to test authentication scenarios.
Allows providing custom examples for testAuth via an object.
Simulates service requests that trigger desiered condition paths in tests.
* Add authOverride to testAuth
Some classes can change the auth based on badge inputs.
This parameter allows the flexability of overriding the default auth for testing those cases.
* Add configOverride to testAuth
Some tests might require non default config for cases where these are set.
This allows creating tests for those cases.
* Fix example params by split into path and query
Splits testAuth example params into path and query params.
Introduce paramType to getBadgeExampleCall
* Refactor BitbucketPullRequest for testAuth
Refactor to add auth static properties.
for better integration with testAuth.
Refactor bitbucketpullrequest for testAuth
* Refactor: use testAuth for BitbucketPullRequest
* Fix BitbucketPullRequest tests using authOverride
* Add auth testing for jenkins services with testAuth
* Add auth testing for Jira services with testAuth
* Add auth testing for Nexus services with testAuth
* Improve error handling in getServiceClassAuthOrigin
Enhance reliability by throwing a TypeError when a service key definition is missing.
It's common for a key to be missing and might require the developer that writes tests to provide a fake on that fits the examples used.
Key changes:
- Added a check for missing service key definitions in getServiceClassAuthOrigin.
- Throws a TypeError with a clear message if the key is not found.
- Guides devs to use an override if needed which is often.
* Fix edge case in testAuth for user only auth
Addresses a scenario where generateFakeConfig/testAuth would fail for classes using auth.userKey without auth.passKey.
Ensures proper handling of user-specific authentication even if a password key is not present.
Throws a TypeError only when both fakeKey and fakeUser are missing.
Better fit for AuthHelper behivor.
* Add option to not import openApi example in testAuth
Added for services without openApi examples.
Dev can use example override to add example inputs in those cases.
* Add auth testing for Sonar services with testAuth
* Add auth testing for SymfonyInsight services with testAuth
* Refactor TeamCity auth tests for use of testAuth
* Refactor testAuth function to handle defaultToEmptyStringForUser auth option
* Add support for multiple requests in testAuth function
Some services might have more then one request to auth with the server for the same shield.
This commit adds support for those requests in testAuth using the new multipleRequests option.
* Add auth testing for AzureDevOps services with testAuth
* Fix async mocha tests
Missing return for async mocha tests caused the tests to run async and throw errors of one test in another.
This commit makes sure all testAuth tests return a promise to mocha for it to await.
* Remove ignoreOpenApiExample option in testAuth function
The `ignoreOpenApiExample` option in the `testAuth` function is no longer needed and has been removed. This option was used to ignore OpenAPI examples for classes without OpenAPI, but it is no longer necessary as the function now handles this case correctly.
BaseService defines by dafault empty object for openApi so if nothing is set we expect empty obj.
Warn devs about missing openApi as openApi is standard for services now.
* handle extraction of openApi boolean examples
Improve authTest by handeling boolean example extractions.
Remove example override not needed after this change.
* Use static headers in base service classes and remove contentType option from testAuth
Refactor the base service classes (BaseGraphqlService, BaseJsonService, BaseSvgScrapingService, BaseTomlService, BaseXmlService, BaseYamlService) to use static headers for access from other function to header types.
Remove testAuth contentType option and use the new headers veriable to extract headers insted.
* Remove contentType option tests using testAuth
This option is removed
* Update jenkinsCoverage response
Example changed at 62ed7c3a27
The new example schema differ from old one
This caused test to fail
Update example response to fit new schema
* remove BitbucketPullReuqest tests
remove for adding these changes in a later PR.
this test adds the authOverride we try to get rid of.
This blocks testAuth development and is planned for a later time.
* fix: fix wrong exception message & check order
* fix typo
Co-authored-by: Pierre-Yves Bigourdan <10694593+PyvesB@users.noreply.github.com>
* fix typo cleanup -> clean up
Co-authored-by: Pierre-Yves Bigourdan <10694593+PyvesB@users.noreply.github.com>
* fix exception error text 'object' -> 'boolean'
Co-authored-by: Pierre-Yves Bigourdan <10694593+PyvesB@users.noreply.github.com>
* fix: return merged authorizedOrigins in getServiceClassAuthOrigin
* update JenkinsTests origin
Was outdated after merging with master.
This commit fixes origin test to openapi example.
* fix(docs): docstring origins type
* fix typo
* fix(auth): reduce strictness for JwtAuth test
Avoid exact body match requirement.
We are only intrested in username and password values to match, not exact one to one object.
---------
Co-authored-by: Pierre-Yves Bigourdan <10694593+PyvesB@users.noreply.github.com>
* 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: simplify AzureDevOpsTests service tests via helpers
* refactor: apply standard service class patterns to AzureDevOpsTests class
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
* Support Azure DevOps badge on a specific stage or job
* Add samples
* Fix tests
* Restart CI
* Changes per @PyvesB review
Co-authored-by: Pierre-Yves B. <PyvesDev@gmail.com>
* set followRedirect: false by default in tests
* update tests implicitly relying on redirects
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
* Convert remaining tests to use expectRedirect() helper
* convert last few redirect tests to use svg not json
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This is a reworking of #3410 based on some feedback @calebcartwright left on that PR.
The goals of injecting the secrets are threefold:
1. Simplify testing
2. Be consistent with all of the other config (which is injected)
3. Encapsulate the sensitive auth-related code in one place so it can be studied and tested thoroughly
- Rather than add more code to BaseService to handle authorization logic, it delegates that to an AuthHelper class.
- When the server starts, it fetches the credentials from `config` and injects them into `BaseService.register()` which passes them to `invoke()`.
- In `invoke()` the service's auth configuration is checked (`static get auth()`, much like `static get route()`).
- If the auth config is present, an AuthHelper instance is created and attached to the new instance.
- Then within the service, the password, basic auth config, or bearer authentication can be accessed via e.g. `this.authHelper.basicAuth` and passed to `this._requestJson()` and friends.
- Everything is being done very explicitly, so it should be very clear where and how the configured secrets are being used.
- Testing different configurations of services can now be done by injecting the config into `invoke()` in `.spec` files instead of mocking global state in the service tests as was done before. See the new Jira spec files for a good example of this.
Ref #3393
* 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
As described in #2340, this provides a way to replace an old alias with a redirect. This makes it easier to migrate our URLs over time without making our matching patterns more complicated.
The 301 redirect is sent back to the requester. If a user pastes the aliased URL into the address bar, it'll be replaced in the browser with the new URL, which gently encourages them to migrate.
Close#2340
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.
* fix: updated Azure DevOps fetch function to reflect query param name change
* fix: fixed branch filter for azure devops to enable branch name usage
* fix: simplified branch pattern for azure devops badges
* Fix orange statuses
* Add test for partially succeeded build
* Add service test for partially succeeded builds
* Add service test for partially succeeded builds