-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(internal): fix http coverage (#6746)
- Loading branch information
Showing
12 changed files
with
453 additions
and
228 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`util/http/bitbucket-server posts 1`] = ` | ||
Array [ | ||
Object { | ||
"headers": Object { | ||
"accept": "application/json", | ||
"accept-encoding": "gzip, deflate", | ||
"authorization": "Bearer token", | ||
"host": "git.example.com", | ||
"user-agent": "https://github.com/renovatebot/renovate", | ||
"x-atlassian-token": "no-check", | ||
}, | ||
"method": "POST", | ||
"url": "https://git.example.com/some-url", | ||
}, | ||
] | ||
`; |
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,108 +1,151 @@ | ||
import { getName } from '../../../test/util'; | ||
import { removeAuthorization } from './auth'; | ||
import { PLATFORM_TYPE_GITEA } from '../../constants/platforms'; | ||
import { applyAuthorization, removeAuthorization } from './auth'; | ||
|
||
describe(getName(__filename), () => { | ||
it('removeAuthorization no authorization', () => { | ||
const opts = { | ||
hostname: 'amazon.com', | ||
href: 'https://amazon.com', | ||
search: 'something X-Amz-Algorithm something', | ||
}; | ||
|
||
removeAuthorization(opts); | ||
|
||
expect(opts).toEqual({ | ||
hostname: 'amazon.com', | ||
href: 'https://amazon.com', | ||
search: 'something X-Amz-Algorithm something', | ||
describe('applyAuthorization', () => { | ||
it('does nothing', () => { | ||
const opts = { | ||
hostname: 'amazon.com', | ||
href: 'https://amazon.com', | ||
auth: 'XXXX', | ||
}; | ||
|
||
applyAuthorization(opts); | ||
|
||
expect(opts).toMatchInlineSnapshot(` | ||
Object { | ||
"auth": "XXXX", | ||
"hostname": "amazon.com", | ||
"href": "https://amazon.com", | ||
} | ||
`); | ||
}); | ||
}); | ||
|
||
it('removeAuthorization Amazon', () => { | ||
const opts = { | ||
auth: 'auth', | ||
headers: { | ||
authorization: 'auth', | ||
}, | ||
hostname: 'amazon.com', | ||
href: 'https://amazon.com', | ||
search: 'something X-Amz-Algorithm something', | ||
}; | ||
|
||
removeAuthorization(opts); | ||
|
||
expect(opts).toEqual({ | ||
headers: {}, | ||
hostname: 'amazon.com', | ||
href: 'https://amazon.com', | ||
search: 'something X-Amz-Algorithm something', | ||
it('gittea token', () => { | ||
const opts = { | ||
headers: {}, | ||
token: 'XXXX', | ||
hostType: PLATFORM_TYPE_GITEA, | ||
}; | ||
|
||
applyAuthorization(opts); | ||
|
||
expect(opts).toMatchInlineSnapshot(` | ||
Object { | ||
"headers": Object { | ||
"authorization": "token XXXX", | ||
}, | ||
"hostType": "gitea", | ||
"token": "XXXX", | ||
} | ||
`); | ||
}); | ||
}); | ||
|
||
it('removeAuthorization Amazon ports', () => { | ||
const opts = { | ||
auth: 'auth', | ||
headers: { | ||
authorization: 'auth', | ||
}, | ||
hostname: 'amazon.com', | ||
href: 'https://amazon.com', | ||
port: 3000, | ||
search: 'something X-Amz-Algorithm something', | ||
}; | ||
|
||
removeAuthorization(opts); | ||
|
||
expect(opts).toEqual({ | ||
headers: {}, | ||
hostname: 'amazon.com', | ||
href: 'https://amazon.com', | ||
search: 'something X-Amz-Algorithm something', | ||
describe('removeAuthorization', () => { | ||
it('no authorization', () => { | ||
const opts = { | ||
hostname: 'amazon.com', | ||
href: 'https://amazon.com', | ||
search: 'something X-Amz-Algorithm something', | ||
}; | ||
|
||
removeAuthorization(opts); | ||
|
||
expect(opts).toEqual({ | ||
hostname: 'amazon.com', | ||
href: 'https://amazon.com', | ||
search: 'something X-Amz-Algorithm something', | ||
}); | ||
}); | ||
}); | ||
|
||
it('removeAuthorization Azure blob', () => { | ||
const opts = { | ||
auth: 'auth', | ||
headers: { | ||
authorization: 'auth', | ||
}, | ||
hostname: 'store123.blob.core.windows.net', | ||
href: | ||
'https://<store>.blob.core.windows.net/<some id>//docker/registry/v2/blobs', | ||
}; | ||
|
||
removeAuthorization(opts); | ||
|
||
expect(opts).toEqual({ | ||
headers: {}, | ||
hostname: 'store123.blob.core.windows.net', | ||
href: | ||
'https://<store>.blob.core.windows.net/<some id>//docker/registry/v2/blobs', | ||
it('Amazon', () => { | ||
const opts = { | ||
auth: 'auth', | ||
headers: { | ||
authorization: 'auth', | ||
}, | ||
hostname: 'amazon.com', | ||
href: 'https://amazon.com', | ||
search: 'something X-Amz-Algorithm something', | ||
}; | ||
|
||
removeAuthorization(opts); | ||
|
||
expect(opts).toEqual({ | ||
headers: {}, | ||
hostname: 'amazon.com', | ||
href: 'https://amazon.com', | ||
search: 'something X-Amz-Algorithm something', | ||
}); | ||
}); | ||
}); | ||
|
||
it('removeAuthorization keep auth', () => { | ||
const opts = { | ||
auth: 'auth', | ||
headers: { | ||
authorization: 'auth', | ||
}, | ||
hostname: 'renovate.com', | ||
href: 'https://renovate.com', | ||
search: 'something', | ||
}; | ||
|
||
removeAuthorization(opts); | ||
|
||
expect(opts).toEqual({ | ||
auth: 'auth', | ||
headers: { | ||
authorization: 'auth', | ||
}, | ||
hostname: 'renovate.com', | ||
href: 'https://renovate.com', | ||
search: 'something', | ||
it('Amazon ports', () => { | ||
const opts = { | ||
auth: 'auth', | ||
headers: { | ||
authorization: 'auth', | ||
}, | ||
hostname: 'amazon.com', | ||
href: 'https://amazon.com', | ||
port: 3000, | ||
search: 'something X-Amz-Algorithm something', | ||
}; | ||
|
||
removeAuthorization(opts); | ||
|
||
expect(opts).toEqual({ | ||
headers: {}, | ||
hostname: 'amazon.com', | ||
href: 'https://amazon.com', | ||
search: 'something X-Amz-Algorithm something', | ||
}); | ||
}); | ||
|
||
it('Azure blob', () => { | ||
const opts = { | ||
auth: 'auth', | ||
headers: { | ||
authorization: 'auth', | ||
}, | ||
hostname: 'store123.blob.core.windows.net', | ||
href: | ||
'https://<store>.blob.core.windows.net/<some id>//docker/registry/v2/blobs', | ||
}; | ||
|
||
removeAuthorization(opts); | ||
|
||
expect(opts).toEqual({ | ||
headers: {}, | ||
hostname: 'store123.blob.core.windows.net', | ||
href: | ||
'https://<store>.blob.core.windows.net/<some id>//docker/registry/v2/blobs', | ||
}); | ||
}); | ||
|
||
it('keep auth', () => { | ||
const opts = { | ||
auth: 'auth', | ||
headers: { | ||
authorization: 'auth', | ||
}, | ||
hostname: 'renovate.com', | ||
href: 'https://renovate.com', | ||
search: 'something', | ||
}; | ||
|
||
removeAuthorization(opts); | ||
|
||
expect(opts).toEqual({ | ||
auth: 'auth', | ||
headers: { | ||
authorization: 'auth', | ||
}, | ||
hostname: 'renovate.com', | ||
href: 'https://renovate.com', | ||
search: 'something', | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as httpMock from '../../../test/httpMock'; | ||
import { getName } from '../../../test/util'; | ||
import { PLATFORM_TYPE_BITBUCKET_SERVER } from '../../constants/platforms'; | ||
import * as hostRules from '../host-rules'; | ||
import { BitbucketServerHttp, setBaseUrl } from './bitbucket-server'; | ||
|
||
const baseUrl = 'https://git.example.com'; | ||
|
||
describe(getName(__filename), () => { | ||
let api: BitbucketServerHttp; | ||
beforeEach(() => { | ||
api = new BitbucketServerHttp(); | ||
|
||
// reset module | ||
jest.resetAllMocks(); | ||
|
||
// clean up hostRules | ||
hostRules.clear(); | ||
hostRules.add({ | ||
hostType: PLATFORM_TYPE_BITBUCKET_SERVER, | ||
baseUrl, | ||
token: 'token', | ||
}); | ||
|
||
httpMock.reset(); | ||
httpMock.setup(); | ||
|
||
setBaseUrl(baseUrl); | ||
}); | ||
it('posts', async () => { | ||
const body = ['a', 'b']; | ||
httpMock.scope(baseUrl).post('/some-url').reply(200, body); | ||
const res = await api.postJson('some-url'); | ||
expect(res.body).toEqual(body); | ||
expect(httpMock.getTrace()).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.