Skip to content

Commit

Permalink
remove BitbucketPullReuqest tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jNullj committed Oct 3, 2024
1 parent 73b3e14 commit 1fdf395
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 95 deletions.
34 changes: 15 additions & 19 deletions services/bitbucket/bitbucket-pull-request.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ function pullRequestClassGenerator(raw) {
queryParamSchema,
}

static auth = {
userKey: 'bitbucket_username',
passKey: 'bitbucket_password',
serviceKey: 'bitbucket',
isRequired: true,
}

static authServer = {
userKey: 'bitbucket_server_username',
passKey: 'bitbucket_server_password',
serviceKey: 'bitbucketServer',
isRequired: true,
}

static get openApi() {
const key = `/bitbucket/${routePrefix}/{user}/{repo}`
const route = {}
Expand Down Expand Up @@ -85,16 +71,27 @@ function pullRequestClassGenerator(raw) {
constructor(context, config) {
super(context, config)

// can only be set here as we must get config
this.bitbucketAuthHelper = new AuthHelper(
{
userKey: 'bitbucket_username',
passKey: 'bitbucket_password',
authorizedOrigins: ['https://bitbucket.org'],
},
config,
)
this.bitbucketServerAuthHelper = new AuthHelper(
BitbucketPullRequest.authServer,
{
userKey: 'bitbucket_server_username',
passKey: 'bitbucket_server_password',
serviceKey: 'bitbucketServer',
},
config,
)
}

async fetchCloud({ user, repo }) {
return this._requestJson(
this.authHelper.withBasicAuth({
this.bitbucketAuthHelper.withBasicAuth({
url: `https://bitbucket.org/api/2.0/repositories/${user}/${repo}/pullrequests/`,
schema,
options: { searchParams: { state: 'OPEN', limit: 0 } },
Expand All @@ -106,7 +103,7 @@ function pullRequestClassGenerator(raw) {
// https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html#idm46229602363312
async fetchServer({ server, user, repo }) {
return this._requestJson(
this.authHelper.withBasicAuth({
this.bitbucketServerAuthHelper.withBasicAuth({
url: `${server}/rest/api/1.0/projects/${user}/repos/${repo}/pull-requests`,
schema,
options: {
Expand All @@ -124,7 +121,6 @@ function pullRequestClassGenerator(raw) {

async fetch({ server, user, repo }) {
if (server !== undefined) {
this.authHelper = this.bitbucketServerAuthHelper
return this.fetchServer({ server, user, repo })
} else {
return this.fetchCloud({ user, repo })
Expand Down
134 changes: 58 additions & 76 deletions services/bitbucket/bitbucket-pull-request.spec.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,73 @@
import { testAuth } from '../test-helpers.js'
import {
BitbucketRawPullRequests,
BitbucketNonRawPullRequests,
} from './bitbucket-pull-request.service.js'
import { expect } from 'chai'
import nock from 'nock'
import { cleanUpNockAfterEach, defaultContext } from '../test-helpers.js'
import { BitbucketRawPullRequests } from './bitbucket-pull-request.service.js'

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',
},
}
describe('BitbucketPullRequest', function () {
cleanUpNockAfterEach()

const cloudConfigOverride = {
public: {
services: {
bitbucket: {
authorizedOrigins: ['https://bitbucket.org'],
},
bitbucketServer: {
authorizedOrigins: [],
},
},
},
}
const user = 'admin'
const pass = 'password'

describe('BitbucketRawPullRequests', function () {
describe('auth', function () {
it('sends the auth information to Bitbucket cloud as configured', async function () {
return testAuth(
BitbucketRawPullRequests,
'BasicAuth',
{ size: 42 },
{
exampleOverride: { server: undefined },
configOverride: cloudConfigOverride,
},
)
})
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 })

it('sends the auth information to Bitbucket instence as configured', async function () {
return testAuth(
BitbucketRawPullRequests,
'BasicAuth',
{ size: 42 },
expect(
await BitbucketRawPullRequests.invoke(
defaultContext,
{
authOverride: BitbucketRawPullRequests.authServer,
configOverride: serverConfigOverride,
public: {
services: {
bitbucketServer: {
authorizedOrigins: [],
},
},
},
private: { bitbucket_username: user, bitbucket_password: pass },
},
)
{ user: 'shields-io', repo: 'test-repo' },
),
).to.deep.equal({
message: '42',
color: 'yellow',
})

scope.done()
})
})

describe('BitbucketNonRawPullRequests', function () {
describe('auth', function () {
it('sends the auth information to Bitbucket cloud as configured', async function () {
return testAuth(
BitbucketNonRawPullRequests,
'BasicAuth',
{ size: 42 },
{
exampleOverride: { server: undefined },
configOverride: cloudConfigOverride,
},
)
})
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 })

it('sends the auth information to Bitbucket instence as configured', async function () {
return testAuth(
BitbucketNonRawPullRequests,
'BasicAuth',
{ size: 42 },
expect(
await BitbucketRawPullRequests.invoke(
defaultContext,
{
authOverride: BitbucketNonRawPullRequests.authServer,
configOverride: serverConfigOverride,
public: {
services: {
bitbucketServer: {
authorizedOrigins: ['https://bitbucket.example.test'],
},
},
},
private: {
bitbucket_server_username: user,
bitbucket_server_password: pass,
},
},
)
{ user: 'project', repo: 'repo' },
{ server: 'https://bitbucket.example.test' },
),
).to.deep.equal({
message: '42',
color: 'yellow',
})

scope.done()
})
})

0 comments on commit 1fdf395

Please sign in to comment.