Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve our approach for testing auth (part 2) - basicAuth #9983

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
764582e
improve stackexchange auth testing
jNullj Oct 23, 2023
2e913a7
Merge branch 'master' into feat/9493/improve-auth-testing
jNullj Oct 23, 2023
ae1a231
Merge branch 'badges:master' into feat/9493/improve-auth-testing
jNullj Jan 6, 2024
b2c2a18
Merge branch 'badges:master' into feat/9493/improve-auth-testing
jNullj Jan 6, 2024
9dd597d
Remove dummy auth test
jNullj Jan 16, 2024
7bc3cc0
Add getBadgeExampleCall to test-helpers
jNullj Jan 20, 2024
f6da3af
Use getBadgeExampleCall in stackexchange-base tests
jNullj Jan 20, 2024
31c3f94
Fix getBadgeExampleCall Errors
jNullj Jan 20, 2024
18ec387
Add testAuth to test-helpers
jNullj Jan 20, 2024
1688e58
Refactor stackexchange-base.spec.js to use testAuth from test-helpers
jNullj Jan 20, 2024
609c017
Split stackexchange-base.spec into per service test file
jNullj Jan 20, 2024
ffc7800
Add all auth methods to testAuth
jNullj Feb 10, 2024
3e5c98d
Handle non-default bearer and api headers
jNullj Feb 11, 2024
876708f
Add discord.spec.js as first attempt for bearer auth
jNullj Feb 11, 2024
1ddd577
Merge branch 'badges:master' into feat/9493/improve-auth-testing
jNullj Feb 11, 2024
c41f60f
Fix basic auth user
jNullj Feb 11, 2024
f4cc1af
Add dynamic authorizedOrigins
jNullj Feb 11, 2024
b471c5c
Add header optional argument
jNullj Feb 11, 2024
7aadc10
Add obs as basicAuth example
jNullj Feb 11, 2024
79dc536
Use apiHeaderKey and bearerHeaderKey function params
jNullj Feb 13, 2024
d1435c2
Remove old comment
jNullj Feb 13, 2024
a53f716
Allow any pass & user key for QueryStringAuth
jNullj Feb 16, 2024
14d0789
Add auth test for PepyDownloads
jNullj Feb 16, 2024
d22de8a
Fix wrong header for jwt login
jNullj Feb 16, 2024
50f4144
Support multiple authOrigins in testAuth
jNullj Feb 16, 2024
2d310bd
Add docker-automated auth test
jNullj Feb 16, 2024
1b79b4c
Fix JwtAuth testing by introducing mandatory jwtLoginEndpoint
jNullj Feb 17, 2024
419bd01
Merge branch 'badges:master' into feat/9493/improve-auth-testing
jNullj Feb 17, 2024
a2b838c
Fix type test in generateFakeConfig
jNullj Feb 20, 2024
2590482
Merge branch 'badges:master' into feat/9493/improve-auth-testing
jNullj Feb 22, 2024
4d57607
Add exampleOverride to testAuth
jNullj Feb 22, 2024
f156762
Add authOverride to testAuth
jNullj Feb 23, 2024
cd6c65b
Add configOverride to testAuth
jNullj Feb 23, 2024
cf34fae
Fix example params by split into path and query
jNullj Feb 24, 2024
8adaf3d
Refactor BitbucketPullRequest for testAuth
jNullj Feb 23, 2024
988290d
Refactor: use testAuth for BitbucketPullRequest
jNullj Feb 22, 2024
b9d51d1
Fix BitbucketPullRequest tests using authOverride
jNullj Feb 23, 2024
b23e3d4
Add auth testing for jenkins services with testAuth
jNullj Feb 25, 2024
84bee80
Add auth testing for Jira services with testAuth
jNullj Mar 2, 2024
1c15782
Add auth testing for Nexus services with testAuth
jNullj Mar 2, 2024
a713669
Improve error handling in getServiceClassAuthOrigin
jNullj Mar 9, 2024
99a01e1
Fix edge case in testAuth for user only auth
jNullj Mar 9, 2024
74554d7
Add option to not import openApi example in testAuth
jNullj Mar 9, 2024
8b8bf19
Add auth testing for Sonar services with testAuth
jNullj Mar 9, 2024
a2b5331
Add auth testing for SymfonyInsight services with testAuth
jNullj Mar 22, 2024
87c68e2
Refactor TeamCity auth tests for use of testAuth
jNullj Mar 22, 2024
8c38355
Refactor testAuth function to handle defaultToEmptyStringForUser auth…
jNullj Mar 24, 2024
57163eb
Add support for multiple requests in testAuth function
jNullj Mar 24, 2024
5dc774a
Add auth testing for AzureDevOps services with testAuth
jNullj Mar 24, 2024
1b425aa
Fix async mocha tests
jNullj Apr 6, 2024
94a479a
Merge branch 'master' into feat/9493/improve-auth-testing
jNullj Apr 6, 2024
ee75674
Merge branch 'master' into feat/9493/improve-auth-testing
jNullj Jun 8, 2024
263aba7
Remove ignoreOpenApiExample option in testAuth function
jNullj Jun 8, 2024
669d913
handle extraction of openApi boolean examples
jNullj Jun 8, 2024
625042e
Use static headers in base service classes and remove contentType opt…
jNullj Jun 12, 2024
059b8ca
Remove contentType option tests using testAuth
jNullj Jun 12, 2024
9e58dde
Merge branch 'master' into feat/9493/improve-auth-testing
jNullj Oct 3, 2024
73b3e14
Update jenkinsCoverage response
jNullj Oct 3, 2024
1fdf395
remove BitbucketPullReuqest tests
jNullj Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/custom-environment-variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public:
__format: 'json'

services:
bitbucket:
authorizedOrigins: 'BITBUCKET_ORIGINS'
bitbucketServer:
authorizedOrigins: 'BITBUCKET_SERVER_ORIGINS'
drone:
Expand Down
2 changes: 2 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public:
cors:
allowedOrigin: []
services:
bitbucket:
authorizedOrigins: 'https://bitbucket.org'
github:
baseUri: 'https://api.github.com'
debug:
Expand Down
4 changes: 3 additions & 1 deletion core/base-service/base-graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class BaseGraphqlService extends BaseService {
return parseJson(buffer)
}

static headers = { Accept: 'application/json' }

/**
* Request data from an upstream GraphQL API,
* parse it and validate against a schema
Expand Down Expand Up @@ -76,7 +78,7 @@ class BaseGraphqlService extends BaseService {
transformErrors = defaultTransformErrors,
}) {
const mergedOptions = {
...{ headers: { Accept: 'application/json' } },
...{ headers: this.constructor.headers },
...options,
}
mergedOptions.method = 'POST'
Expand Down
4 changes: 3 additions & 1 deletion core/base-service/base-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class BaseJsonService extends BaseService {
return parseJson(buffer)
}

static headers = { Accept: 'application/json' }

/**
* Request data from an upstream API serving JSON,
* parse it and validate against a schema
Expand Down Expand Up @@ -54,7 +56,7 @@ class BaseJsonService extends BaseService {
logErrors = [429],
}) {
const mergedOptions = {
...{ headers: { Accept: 'application/json' } },
...{ headers: this.constructor.headers },
...options,
}
const { buffer } = await this._request({
Expand Down
4 changes: 3 additions & 1 deletion core/base-service/base-svg-scraping.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class BaseSvgScrapingService extends BaseService {
}
}

static headers = { Accept: 'image/svg+xml' }

/**
* Request data from an endpoint serving SVG,
* parse a value from it and validate against a schema
Expand Down Expand Up @@ -79,7 +81,7 @@ class BaseSvgScrapingService extends BaseService {
}) {
const logTrace = (...args) => trace.logTrace('fetch', ...args)
const mergedOptions = {
...{ headers: { Accept: 'image/svg+xml' } },
...{ headers: this.constructor.headers },
...options,
}
const { buffer } = await this._request({
Expand Down
18 changes: 9 additions & 9 deletions core/base-service/base-toml.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ import trace from './trace.js'
* @abstract
*/
class BaseTomlService extends BaseService {
static headers = {
Accept:
// the official header should be application/toml - see https://toml.io/en/v1.0.0#mime-type
// but as this is not registered here https://www.iana.org/assignments/media-types/media-types.xhtml
// some apps use other mime-type like application/x-toml, text/plain etc....
'text/x-toml, text/toml, application/x-toml, application/toml, text/plain',
}

/**
* Request data from an upstream API serving TOML,
* parse it and validate against a schema
Expand Down Expand Up @@ -48,15 +56,7 @@ class BaseTomlService extends BaseService {
}) {
const logTrace = (...args) => trace.logTrace('fetch', ...args)
const mergedOptions = {
...{
headers: {
Accept:
// the official header should be application/toml - see https://toml.io/en/v1.0.0#mime-type
// but as this is not registered here https://www.iana.org/assignments/media-types/media-types.xhtml
// some apps use other mime-type like application/x-toml, text/plain etc....
'text/x-toml, text/toml, application/x-toml, application/toml, text/plain',
},
},
...{ headers: this.constructor.headers },
...options,
}
const { buffer } = await this._request({
Expand Down
4 changes: 3 additions & 1 deletion core/base-service/base-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { InvalidResponse } from './errors.js'
* @abstract
*/
class BaseXmlService extends BaseService {
static headers = { Accept: 'application/xml, text/xml' }

/**
* Request data from an upstream API serving XML,
* parse it and validate against a schema
Expand Down Expand Up @@ -53,7 +55,7 @@ class BaseXmlService extends BaseService {
}) {
const logTrace = (...args) => trace.logTrace('fetch', ...args)
const mergedOptions = {
...{ headers: { Accept: 'application/xml, text/xml' } },
...{ headers: this.constructor.headers },
...options,
}
const { buffer } = await this._request({
Expand Down
12 changes: 6 additions & 6 deletions core/base-service/base-yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import trace from './trace.js'
* @abstract
*/
class BaseYamlService extends BaseService {
static headers = {
Accept:
'text/x-yaml, text/yaml, application/x-yaml, application/yaml, text/plain',
}

/**
* Request data from an upstream API serving YAML,
* parse it and validate against a schema
Expand Down Expand Up @@ -50,12 +55,7 @@ class BaseYamlService extends BaseService {
}) {
const logTrace = (...args) => trace.logTrace('fetch', ...args)
const mergedOptions = {
...{
headers: {
Accept:
'text/x-yaml, text/yaml, application/x-yaml, application/yaml, text/plain',
},
},
...{ headers: this.constructor.headers },
...options,
}
const { buffer } = await this._request({
Expand Down
1 change: 1 addition & 0 deletions core/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const publicConfigSchema = Joi.object({
allowedOrigin: Joi.array().items(optionalUrl).required(),
},
services: Joi.object({
bitbucket: defaultService,
bitbucketServer: defaultService,
drone: defaultService,
github: {
Expand Down
33 changes: 33 additions & 0 deletions services/azure-devops/azure-devops-coverage.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { testAuth } from '../test-helpers.js'
import AzureDevOpsCoverage from './azure-devops-coverage.service.js'

describe('AzureDevOpsCoverage', function () {
describe('auth', function () {
it('sends the auth information as configured', async function () {
return testAuth(
AzureDevOpsCoverage,
'BasicAuth',
{
coverageData: [
{
coverageStats: [
{
label: 'Coverage',
total: 95,
covered: 93,
},
],
},
],
count: 1,
value: [
{
id: 90395,
},
],
},
{ multipleRequests: true },
)
})
})
})
32 changes: 32 additions & 0 deletions services/azure-devops/azure-devops-tests.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { testAuth } from '../test-helpers.js'
import AzureDevOpsTests from './azure-devops-tests.service.js'

describe('AzureDevOpsTests', function () {
describe('auth', function () {
it('sends the auth information as configured', async function () {
return testAuth(
AzureDevOpsTests,
'BasicAuth',
{
aggregatedResultsAnalysis: {
totalTests: 95,
resultsByOutcome: {
Passed: {
count: 93,
},
},
},
count: 1,
value: [
{
id: 90395,
},
],
},
{
multipleRequests: true,
},
)
})
})
})
62 changes: 17 additions & 45 deletions services/jenkins/jenkins-build.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { expect } from 'chai'
import nock from 'nock'
import { test, forCases, given } from 'sazerac'
import { renderBuildStatusBadge } from '../build-status.js'
import { cleanUpNockAfterEach, defaultContext } from '../test-helpers.js'
import { testAuth } from '../test-helpers.js'
import JenkinsBuild from './jenkins-build.service.js'

const authConfigOverride = {
public: {
services: {
jenkins: {
authorizedOrigins: ['https://ci.eclipse.org'],
},
},
},
}

describe('JenkinsBuild', function () {
test(JenkinsBuild.prototype.transform, () => {
forCases([
Expand Down Expand Up @@ -57,49 +65,13 @@ describe('JenkinsBuild', function () {
})

describe('auth', function () {
cleanUpNockAfterEach()

const user = 'admin'
const pass = 'password'
const config = {
public: {
services: {
jenkins: {
authorizedOrigins: ['https://jenkins.ubuntu.com'],
},
},
},
private: {
jenkins_user: user,
jenkins_pass: pass,
},
}

it('sends the auth information as configured', async function () {
const scope = nock('https://jenkins.ubuntu.com')
.get('/server/job/curtin-vmtest-daily-x/api/json?tree=color')
// 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.
.basicAuth({ user, pass })
.reply(200, { color: 'blue' })

expect(
await JenkinsBuild.invoke(
defaultContext,
config,
{},
{
jobUrl:
'https://jenkins.ubuntu.com/server/job/curtin-vmtest-daily-x',
},
),
).to.deep.equal({
label: undefined,
message: 'passing',
color: 'brightgreen',
})

scope.done()
return testAuth(
JenkinsBuild,
'BasicAuth',
{ color: 'blue' },
{ configOverride: authConfigOverride },
)
})
})
})
25 changes: 25 additions & 0 deletions services/jenkins/jenkins-coverage.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { testAuth } from '../test-helpers.js'
import JenkinsCoverage from './jenkins-coverage.service.js'

const authConfigOverride = {
public: {
services: {
jenkins: {
authorizedOrigins: ['https://ci-maven.apache.org'],
},
},
},
}

describe('JenkinsCoverage', function () {
describe('auth', function () {
it('sends the auth information as configured', async function () {
return testAuth(
JenkinsCoverage,
'BasicAuth',
{ instructionCoverage: { percentage: 93 } },
{ configOverride: authConfigOverride },
)
})
})
})
27 changes: 27 additions & 0 deletions services/jenkins/jenkins-tests.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { testAuth } from '../test-helpers.js'
import JenkinsTests from './jenkins-tests.service.js'

const authConfigOverride = {
public: {
services: {
jenkins: {
authorizedOrigins: ['https://jenkins.sqlalchemy.org'],
},
},
},
}

describe('JenkinsTests', function () {
describe('auth', function () {
it('sends the auth information as configured', async function () {
return testAuth(
JenkinsTests,
'BasicAuth',
{ actions: [{ totalCount: 3, failCount: 2, skipCount: 1 }] },
{
configOverride: authConfigOverride,
},
)
})
})
})
Loading
Loading