forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bitbucket tests with authoverride
part of Improve our approach for testing auth badges#9493 seperated from PR badges#9983 for work in a later time
- Loading branch information
Showing
2 changed files
with
95 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,91 @@ | ||
import { expect } from 'chai' | ||
import nock from 'nock' | ||
import { cleanUpNockAfterEach, defaultContext } from '../test-helpers.js' | ||
import { BitbucketRawPullRequests } from './bitbucket-pull-request.service.js' | ||
import { testAuth } from '../test-helpers.js' | ||
import { | ||
BitbucketRawPullRequests, | ||
BitbucketNonRawPullRequests, | ||
} from './bitbucket-pull-request.service.js' | ||
|
||
describe('BitbucketPullRequest', function () { | ||
cleanUpNockAfterEach() | ||
const serverConfigOverride = { | ||
public: { | ||
services: { | ||
bitbucketServer: { | ||
authorizedOrigins: ['https://bitbucket.mydomain.net'], | ||
}, | ||
bitbucket: { | ||
authorizedOrigins: ['https://bitbucket.org'], | ||
}, | ||
}, | ||
}, | ||
private: { | ||
bitbucket_username: 'must-be-set-for-class-constructor', | ||
bitbucket_password: 'must-be-set-for-class-constructor', | ||
}, | ||
} | ||
|
||
const user = 'admin' | ||
const pass = 'password' | ||
const cloudConfigOverride = { | ||
public: { | ||
services: { | ||
bitbucket: { | ||
authorizedOrigins: ['https://bitbucket.org'], | ||
}, | ||
bitbucketServer: { | ||
authorizedOrigins: [], | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
it('Sends auth headers to Bitbucket as configured', async function () { | ||
const scope = nock('https://bitbucket.org/api/2.0/repositories/') | ||
.get(/.*/) | ||
.basicAuth({ user, pass }) | ||
.reply(200, { size: 42 }) | ||
|
||
expect( | ||
await BitbucketRawPullRequests.invoke( | ||
defaultContext, | ||
describe('BitbucketRawPullRequests', function () { | ||
describe('auth', function () { | ||
it('sends the auth information to Bitbucket cloud as configured', async function () { | ||
return testAuth( | ||
BitbucketRawPullRequests, | ||
'BasicAuth', | ||
{ size: 42 }, | ||
{ | ||
public: { | ||
services: { | ||
bitbucketServer: { | ||
authorizedOrigins: [], | ||
}, | ||
}, | ||
}, | ||
private: { bitbucket_username: user, bitbucket_password: pass }, | ||
exampleOverride: { server: undefined }, | ||
configOverride: cloudConfigOverride, | ||
}, | ||
{ user: 'shields-io', repo: 'test-repo' }, | ||
), | ||
).to.deep.equal({ | ||
message: '42', | ||
color: 'yellow', | ||
) | ||
}) | ||
|
||
scope.done() | ||
it('sends the auth information to Bitbucket instence as configured', async function () { | ||
return testAuth( | ||
BitbucketRawPullRequests, | ||
'BasicAuth', | ||
{ size: 42 }, | ||
{ | ||
authOverride: BitbucketRawPullRequests.authServer, | ||
configOverride: serverConfigOverride, | ||
}, | ||
) | ||
}) | ||
}) | ||
}) | ||
|
||
it('Sends auth headers to Bitbucket Server as configured', async function () { | ||
const scope = nock('https://bitbucket.example.test/rest/api/1.0/projects') | ||
.get(/.*/) | ||
.basicAuth({ user, pass }) | ||
.reply(200, { size: 42 }) | ||
|
||
expect( | ||
await BitbucketRawPullRequests.invoke( | ||
defaultContext, | ||
describe('BitbucketNonRawPullRequests', function () { | ||
describe('auth', function () { | ||
it('sends the auth information to Bitbucket cloud as configured', async function () { | ||
return testAuth( | ||
BitbucketNonRawPullRequests, | ||
'BasicAuth', | ||
{ size: 42 }, | ||
{ | ||
public: { | ||
services: { | ||
bitbucketServer: { | ||
authorizedOrigins: ['https://bitbucket.example.test'], | ||
}, | ||
}, | ||
}, | ||
private: { | ||
bitbucket_server_username: user, | ||
bitbucket_server_password: pass, | ||
}, | ||
exampleOverride: { server: undefined }, | ||
configOverride: cloudConfigOverride, | ||
}, | ||
{ user: 'project', repo: 'repo' }, | ||
{ server: 'https://bitbucket.example.test' }, | ||
), | ||
).to.deep.equal({ | ||
message: '42', | ||
color: 'yellow', | ||
) | ||
}) | ||
|
||
scope.done() | ||
it('sends the auth information to Bitbucket instence as configured', async function () { | ||
return testAuth( | ||
BitbucketNonRawPullRequests, | ||
'BasicAuth', | ||
{ size: 42 }, | ||
{ | ||
authOverride: BitbucketNonRawPullRequests.authServer, | ||
configOverride: serverConfigOverride, | ||
}, | ||
) | ||
}) | ||
}) | ||
}) |