-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
octokit client should follow proxy settings #314
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
507e4be
octokit client should follow proxy settings
ericsciple 45cae67
.
ericsciple 1b905e9
.
ericsciple fe04d29
.
ericsciple 076417c
.
ericsciple 74808ba
.
ericsciple 5c1b20a
.
ericsciple c4a91d3
.
ericsciple da95ba6
.
ericsciple fd75dbc
.
ericsciple 9dafc94
.
ericsciple 8ae50a0
.
ericsciple 75d5d80
.
ericsciple File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import * as http from 'http' | ||
import {GitHub} from '../src/github' | ||
|
||
describe('@actions/github', () => { | ||
let proxyConnects: string[] | ||
let proxyServer: http.Server | ||
let proxyUrl = 'http://127.0.0.1:8080' | ||
let originalProxyUrl = process.env['https_proxy'] | ||
let first = true | ||
|
||
beforeAll(async () => { | ||
// Start proxy server | ||
const proxy = require('proxy') | ||
proxyServer = proxy() as http.Server | ||
await new Promise(resolve => { | ||
const port = Number(proxyUrl.split(':')[2]) | ||
proxyServer.listen(port, () => resolve()) | ||
}) | ||
proxyServer.on('connect', req => { | ||
proxyConnects.push(req.url) | ||
}) | ||
}) | ||
|
||
beforeEach(() => { | ||
delete process.env['https_proxy'] | ||
proxyConnects = [] | ||
}) | ||
|
||
afterAll(async () => { | ||
// Stop proxy server | ||
await new Promise(resolve => { | ||
proxyServer.once('close', () => resolve()) | ||
proxyServer.close() | ||
}) | ||
|
||
if (originalProxyUrl) { | ||
process.env['https_proxy'] = originalProxyUrl | ||
} | ||
}) | ||
|
||
it('basic REST client', async () => { | ||
const token = getToken() | ||
if (!token) { | ||
return | ||
} | ||
|
||
const octokit = new GitHub(token) | ||
const branch = await octokit.repos.getBranch({ | ||
owner: 'actions', | ||
repo: 'toolkit', | ||
branch: 'master' | ||
}) | ||
expect(branch.data.name).toBe('master') | ||
expect(proxyConnects).toHaveLength(0) | ||
}) | ||
|
||
it('basic REST client with custom auth', async () => { | ||
const token = getToken() | ||
if (!token) { | ||
return | ||
} | ||
|
||
// Valid token | ||
let octokit = new GitHub({auth: `token ${token}`}) | ||
let branch = await octokit.repos.getBranch({ | ||
owner: 'actions', | ||
repo: 'toolkit', | ||
branch: 'master' | ||
}) | ||
expect(branch.data.name).toBe('master') | ||
expect(proxyConnects).toHaveLength(0) | ||
|
||
// Invalid token | ||
octokit = new GitHub({auth: `token asdf`}) | ||
let failed = false | ||
try { | ||
await octokit.repos.getBranch({ | ||
owner: 'actions', | ||
repo: 'toolkit', | ||
branch: 'master' | ||
}) | ||
} catch (err) { | ||
failed = true | ||
} | ||
}) | ||
|
||
it('basic REST client with proxy', async () => { | ||
const token = getToken() | ||
if (!token) { | ||
return | ||
} | ||
|
||
process.env['https_proxy'] = proxyUrl | ||
const octokit = new GitHub(token) | ||
const branch = await octokit.repos.getBranch({ | ||
owner: 'actions', | ||
repo: 'toolkit', | ||
branch: 'master' | ||
}) | ||
expect(branch.data.name).toBe('master') | ||
expect(proxyConnects).toEqual(['api.github.com:443']) | ||
}) | ||
|
||
it('basic GraphQL client', async () => { | ||
const token = getToken() | ||
if (!token) { | ||
return | ||
} | ||
|
||
const octokit = new GitHub(token) | ||
const repository = await octokit.graphql( | ||
'{repository(owner:"actions", name:"toolkit"){name}}' | ||
) | ||
expect(repository).toEqual({repository: {name: 'toolkit'}}) | ||
expect(proxyConnects).toHaveLength(0) | ||
}) | ||
|
||
it('basic GraphQL client with custom auth', async () => { | ||
const token = getToken() | ||
if (!token) { | ||
return | ||
} | ||
|
||
// Valid token | ||
let octokit = new GitHub(token) | ||
const repository = await octokit.graphql( | ||
'{repository(owner:"actions", name:"toolkit"){name}}' | ||
) | ||
expect(repository).toEqual({repository: {name: 'toolkit'}}) | ||
expect(proxyConnects).toHaveLength(0) | ||
|
||
// Invalid token | ||
octokit = new GitHub({auth: `token asdf`}) | ||
let failed = false | ||
try { | ||
await octokit.graphql( | ||
'{repository(owner:"actions", name:"toolkit"){name}}' | ||
) | ||
} catch (err) { | ||
failed = true | ||
} | ||
}) | ||
|
||
it('basic GraphQL client with proxy', async () => { | ||
const token = getToken() | ||
if (!token) { | ||
return | ||
} | ||
|
||
process.env['https_proxy'] = proxyUrl | ||
const octokit = new GitHub(token) | ||
const repository = await octokit.graphql( | ||
'{repository(owner:"actions", name:"toolkit"){name}}' | ||
) | ||
expect(repository).toEqual({repository: {name: 'toolkit'}}) | ||
expect(proxyConnects).toEqual(['api.github.com:443']) | ||
}) | ||
|
||
function getToken(): string { | ||
const token = process.env['GITHUB_TOKEN'] || '' | ||
if (!token && first) { | ||
console.warn( | ||
'Skipping GitHub tests. Set $GITHUB_TOKEN to run REST client and GraphQL client tests' | ||
) | ||
first = false | ||
} | ||
|
||
return token | ||
} | ||
}) |
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,3 +1,4 @@ | ||
import * as http from 'http' | ||
import * as path from 'path' | ||
import {Context} from '../src/context' | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New tests to exercise GitHub REST client and GraphQL client with and without proxy
Only runs when env var GITHUB_TOKEN is defined, otherwise warns for discoverability