Skip to content

Commit

Permalink
Make fetching HttpClient optional from context in PKCE auth flow (#4295)
Browse files Browse the repository at this point in the history
* Make fetching HttpClient optional from context in PKCE auth flow

Signed-off-by: pmahindrakar-oss <[email protected]>

* Added log statement

Signed-off-by: pmahindrakar-oss <[email protected]>

* added a unit test

Signed-off-by: pmahindrakar-oss <[email protected]>

* nit : spellcheck

Signed-off-by: pmahindrakar-oss <[email protected]>

---------

Signed-off-by: pmahindrakar-oss <[email protected]>
  • Loading branch information
pmahindrakar-oss authored Oct 24, 2023
1 parent 4fc4988 commit aaea967
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions flyteidl/clients/go/admin/pkce/auth_flow_orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pkce

import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -68,7 +67,8 @@ func (f TokenOrchestrator) FetchTokenFromAuthFlow(ctx context.Context) (*oauth2.
// Pass along http client used in oauth2
httpClient, ok := ctx.Value(oauth2.HTTPClient).(*http.Client)
if !ok {
return nil, errors.New("Unable to retrieve httpClient used in oauth2 from context")
logger.Debugf(ctx, "using default http client instead")
httpClient = http.DefaultClient
}

serveMux.HandleFunc(redirectURL.Path, getAuthServerCallbackHandler(f.ClientConfig, pkceCodeVerifier,
Expand Down
6 changes: 6 additions & 0 deletions flyteidl/clients/go/admin/pkce/auth_flow_orchestrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pkce

import (
"context"
"os/exec"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -29,5 +30,10 @@ func TestFetchFromAuthFlow(t *testing.T) {
refreshedToken, err := orchestrator.FetchTokenFromAuthFlow(ctx)
assert.Nil(t, refreshedToken)
assert.NotNil(t, err)
// Throws an exitError since browser cannot be opened.
// But this makes sure that at least code is tested till the browser action is invoked.
// Earlier change had broken this by introducing a hard dependency on the http Client from the context
_, isAnExitError := err.(*exec.ExitError)
assert.True(t, isAnExitError)
})
}

0 comments on commit aaea967

Please sign in to comment.