preserve err type loginoptions#17138
Conversation
|
/test extended_gssapi |
7f7e973 to
4477cad
Compare
| StartingKubeConfig: &clientcmdapi.Config{}, | ||
| Reader: bytes.NewBufferString("myusername\nmypassword\n"), | ||
| Out: loginOutput, | ||
| ErrOut: loginErrOutput, |
test/integration/oauth_oidc_test.go
Outdated
| StartingKubeConfig: &clientcmdapi.Config{}, | ||
| Reader: bytes.NewBufferString("mylogin\nmypassword\n"), | ||
| Out: loginOutput, | ||
| ErrOut: loginErrOutput, |
pkg/oc/bootstrap/docker/up.go
Outdated
| func (c *ClientStartConfig) Login(out io.Writer) error { | ||
| server := c.OpenShiftHelper().Master(c.ServerIP) | ||
| return openshift.Login(initialUser, initialPassword, server, c.LocalConfigDir, c.originalFactory, c.command, out) | ||
| return openshift.Login(initialUser, initialPassword, server, c.LocalConfigDir, c.originalFactory, c.command, out, ioutil.Discard) |
There was a problem hiding this comment.
It is probably debatable if this should use ioutil.Discard or not.
There was a problem hiding this comment.
The alternative would be to wire each handler to receive a second io.Writer for errs
There was a problem hiding this comment.
why not use the same writer for both? (out)
There was a problem hiding this comment.
the more info we can return to users about failures, etc. the better
There was a problem hiding this comment.
thanks, went ahead and re-used out for both
pkg/oc/cli/cmd/login/loginoptions.go
Outdated
| if statusErr, ok := err.(*kerrors.StatusError); ok { | ||
| if statusErr.Status().Code == http.StatusInternalServerError { | ||
| return fmt.Errorf("error: The server was unable to respond - %v", suggestion) | ||
| fmt.Fprintf(o.ErrOut, "error: The server was unable to respond - %v", suggestion) |
There was a problem hiding this comment.
This needs a newline at the end and you probably want to print the error as well. Not special casing StatusInternalServerError would also be reasonable thing to do.
There was a problem hiding this comment.
Thanks, will go ahead and remove the special case for internal server err - the error we print is pretty much the same as the one below this
|
Do not forget to squash. |
f235ce3 to
21e025b
Compare
pkg/oc/cli/cmd/login/loginoptions.go
Outdated
| token, err := tokencmd.RequestToken(o.Config, o.Reader, o.Username, o.Password) | ||
| if err != nil { | ||
| suggestion := "verify you have provided the correct host and port and that the server is currently running." | ||
| fmt.Fprintf(o.ErrOut, "error: %v - %v\n", err, suggestion) |
There was a problem hiding this comment.
No point in making the suggestion var now.
There was a problem hiding this comment.
thought it might help this line not get too long - will update though
|
@juanvallejo we need some kind of test (unit preferred) to make sure #17150 does not happen. |
8e76c1c to
b366e91
Compare
d63700e to
df1e76b
Compare
|
@enj thanks, added a unit test. ptal |
|
/test extended_conformance_gce |
|
/kind bug |
| // https://tools.ietf.org/html/draft-ietf-oauth-discovery-04#section-2 | ||
| // Copied from pkg/cmd/server/origin/nonapiserver.go | ||
| oauthMetadataEndpoint = "/.well-known/oauth-authorization-server" | ||
| OauthMetadataEndpoint = "/.well-known/oauth-authorization-server" |
There was a problem hiding this comment.
Do not export this, it is already a copy from a different file. Hard code the string, it can never change.
| "testing" | ||
|
|
||
| "github.com/spf13/pflag" | ||
|
|
| func (r *oauthMetadataResponse) Serialize() string { | ||
| b, err := json.Marshal(r.metadata) | ||
| if err != nil { | ||
| return "" |
|
|
||
| if r.URL.Path == tokencmd.OauthMetadataEndpoint { | ||
| w.WriteHeader(http.StatusOK) | ||
| io.WriteString(w, metadataResponse.Serialize()) |
There was a problem hiding this comment.
Can't you just write the raw bytes?
| TokenEndpoint: server.URL + "/oauth/token", | ||
| CodeChallengeMethodsSupported: []string{"plain", "S256"}, | ||
| } | ||
| defer server.Close() |
| } | ||
|
|
||
| if !kapierrs.IsUnauthorized(err) { | ||
| t.Fatalf("expecting error of type metav1.StatusReasonUnauthorized, but got %v", reflect.TypeOf(err)) |
There was a problem hiding this comment.
Can just do %T to get the type.
| return loginOptions | ||
| } | ||
|
|
||
| func defaultClientConfig(flags *pflag.FlagSet) kclientcmd.ClientConfig { |
There was a problem hiding this comment.
Heh, had originally grabbed these two helpers from here. Went ahead and cleaned the test up - no longer need them here
| clientConfig := defaultClientConfig(flagset) | ||
| flagset.Parse(flags) | ||
|
|
||
| startingConfig, _ := clientConfig.RawConfig() |
There was a problem hiding this comment.
If this is an error, it should fail the test.
| metadataResponse := &oauthMetadataResponse{} | ||
|
|
||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| invoked <- struct{}{} |
There was a problem hiding this comment.
You need a check to fail the test if this would dead lock the buffered channel.
5693551 to
1a24880
Compare
|
@enj thanks for the review, comments addressed |
|
/lgtm Approving since this is all auth code. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: enj, juanvallejo Assign the PR to them by writing The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these OWNERS Files:You can indicate your approval by writing |
1a24880 to
b3b6b08
Compare
b3b6b08 to
0c94fae
Compare
|
Automatic merge from submit-queue (batch tested with PRs 17178, 17141, 17138). |
Fixes #17136
Fixes #17150
Preserves the error type returned in https://github.com/openshift/origin/blob/master/pkg/oc/cli/cmd/login/loginoptions.go#L237
cc @openshift/cli-review