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 1) #9681

Merged
merged 29 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 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
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
41 changes: 9 additions & 32 deletions services/discord/discord.spec.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
import { expect } from 'chai'
import nock from 'nock'
import { cleanUpNockAfterEach, defaultContext } from '../test-helpers.js'
import { testAuth } from '../test-helpers.js'
import Discord from './discord.service.js'

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

it('sends the auth information as configured', async function () {
const pass = 'password'
const config = {
private: {
discord_bot_token: pass,
},
}

const scope = nock('https://discord.com', {
// This ensures that the expected credential is actually being sent with the HTTP request.
// Without this the request wouldn't match and the test would fail.
reqheaders: { Authorization: 'Bot password' },
describe('auth', function () {
it('sends the auth information as configured', async function () {
return testAuth(
Discord,
'BearerAuthHeader',
{ presence_count: 125 },
{ bearerHeaderKey: 'Bot' },
)
})
.get('/api/v6/guilds/12345/widget.json')
.reply(200, {
presence_count: 125,
})

expect(
await Discord.invoke(defaultContext, config, {
serverId: '12345',
}),
).to.deep.equal({
message: '125 online',
color: 'brightgreen',
})

scope.done()
})
})
15 changes: 15 additions & 0 deletions services/docker/docker-automated.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { testAuth } from '../test-helpers.js'
import DockerAutomatedBuild from './docker-automated.service.js'

describe('DockerAutomatedBuild', function () {
describe('auth', function () {
it('sends the auth information as configured', async function () {
return testAuth(
DockerAutomatedBuild,
'JwtAuth',
{ is_automated: true },
{ jwtLoginEndpoint: 'https://hub.docker.com/v2/users/login/' },
)
})
})
})
16 changes: 16 additions & 0 deletions services/obs/obs.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { testAuth } from '../test-helpers.js'
import ObsService from './obs.service.js'

describe('ObsService', function () {
describe('auth', function () {
it('sends the auth information as configured', async function () {
return testAuth(
ObsService,
'BasicAuth',
`<?xml version="1.0" encoding="UTF-8"?>
<status package="example" code="passed"></status>`,
{ contentType: 'application/xml' },
)
})
})
})
10 changes: 10 additions & 0 deletions services/pepy/pepy-downloads.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { testAuth } from '../test-helpers.js'
import PepyDownloads from './pepy-downloads.service.js'

describe('PepyDownloads', function () {
describe('auth', function () {
it('sends the auth information as configured', async function () {
return testAuth(PepyDownloads, 'ApiKeyHeader', { total_downloads: 42 })
})
})
})
38 changes: 0 additions & 38 deletions services/stackexchange/stackexchange-base.spec.js

This file was deleted.

17 changes: 17 additions & 0 deletions services/stackexchange/stackexchange-monthlyquestions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { testAuth } from '../test-helpers.js'
import StackExchangeMonthlyQuestions from './stackexchange-monthlyquestions.service.js'

describe('StackExchangeMonthlyQuestions', function () {
describe('auth', function () {
it('sends the auth information as configured', async function () {
return testAuth(
StackExchangeMonthlyQuestions,
'QueryStringAuth',
{
total: 8,
},
{ queryPassKey: 'key' },
)
})
})
})
17 changes: 17 additions & 0 deletions services/stackexchange/stackexchange-reputation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { testAuth } from '../test-helpers.js'
import StackExchangeReputation from './stackexchange-reputation.service.js'

describe('StackExchangeReputation', function () {
describe('auth', function () {
it('sends the auth information as configured', async function () {
return testAuth(
StackExchangeReputation,
'QueryStringAuth',
{
items: [{ reputation: 8 }],
},
{ queryPassKey: 'key' },
)
})
})
})
17 changes: 17 additions & 0 deletions services/stackexchange/stackexchange-taginfo.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { testAuth } from '../test-helpers.js'
import StackExchangeQuestions from './stackexchange-taginfo.service.js'

describe('StackExchangeQuestions', function () {
describe('auth', function () {
it('sends the auth information as configured', async function () {
return testAuth(
StackExchangeQuestions,
'QueryStringAuth',
{
items: [{ count: 8 }],
},
{ queryPassKey: 'key' },
)
})
})
})
Loading
Loading