mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 11:08:10 +00:00
Use the oauth2 context ability to specify a clean http client. (#2808)
Hopefully fixes #2793
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package github
|
package github
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/google/go-github/github"
|
"github.com/google/go-github/github"
|
||||||
"github.com/hashicorp/go-cleanhttp"
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
@@ -63,7 +65,8 @@ type backend struct {
|
|||||||
func (b *backend) Client(token string) (*github.Client, error) {
|
func (b *backend) Client(token string) (*github.Client, error) {
|
||||||
tc := cleanhttp.DefaultClient()
|
tc := cleanhttp.DefaultClient()
|
||||||
if token != "" {
|
if token != "" {
|
||||||
tc = oauth2.NewClient(oauth2.NoContext, &tokenSource{Value: token})
|
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, tc)
|
||||||
|
tc = oauth2.NewClient(ctx, &tokenSource{Value: token})
|
||||||
}
|
}
|
||||||
|
|
||||||
return github.NewClient(tc), nil
|
return github.NewClient(tc), nil
|
||||||
|
|||||||
@@ -48,9 +48,8 @@ func TestBackend_Config(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logicaltest.Test(t, logicaltest.TestCase{
|
logicaltest.Test(t, logicaltest.TestCase{
|
||||||
AcceptanceTest: true,
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
Backend: b,
|
||||||
Backend: b,
|
|
||||||
Steps: []logicaltest.TestStep{
|
Steps: []logicaltest.TestStep{
|
||||||
testConfigWrite(t, config_data1),
|
testConfigWrite(t, config_data1),
|
||||||
testLoginWrite(t, login_data, expectedTTL1.Nanoseconds(), false),
|
testLoginWrite(t, login_data, expectedTTL1.Nanoseconds(), false),
|
||||||
@@ -105,9 +104,8 @@ func TestBackend_basic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logicaltest.Test(t, logicaltest.TestCase{
|
logicaltest.Test(t, logicaltest.TestCase{
|
||||||
AcceptanceTest: true,
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
Backend: b,
|
||||||
Backend: b,
|
|
||||||
Steps: []logicaltest.TestStep{
|
Steps: []logicaltest.TestStep{
|
||||||
testAccStepConfig(t, false),
|
testAccStepConfig(t, false),
|
||||||
testAccMap(t, "default", "fakepol"),
|
testAccMap(t, "default", "fakepol"),
|
||||||
@@ -131,15 +129,15 @@ func TestBackend_basic(t *testing.T) {
|
|||||||
|
|
||||||
func testAccPreCheck(t *testing.T) {
|
func testAccPreCheck(t *testing.T) {
|
||||||
if v := os.Getenv("GITHUB_TOKEN"); v == "" {
|
if v := os.Getenv("GITHUB_TOKEN"); v == "" {
|
||||||
t.Fatal("GITHUB_TOKEN must be set for acceptance tests")
|
t.Skip("GITHUB_TOKEN must be set for acceptance tests")
|
||||||
}
|
}
|
||||||
|
|
||||||
if v := os.Getenv("GITHUB_ORG"); v == "" {
|
if v := os.Getenv("GITHUB_ORG"); v == "" {
|
||||||
t.Fatal("GITHUB_ORG must be set for acceptance tests")
|
t.Skip("GITHUB_ORG must be set for acceptance tests")
|
||||||
}
|
}
|
||||||
|
|
||||||
if v := os.Getenv("GITHUB_BASEURL"); v == "" {
|
if v := os.Getenv("GITHUB_BASEURL"); v == "" {
|
||||||
t.Fatal("GITHUB_BASEURL must be set for acceptance tests (use 'https://api.github.com' if you don't know what you're doing)")
|
t.Skip("GITHUB_BASEURL must be set for acceptance tests (use 'https://api.github.com' if you don't know what you're doing)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user