Report a malformed --account file instead of panicking - #1687
Open
arpitjain099 wants to merge 1 commit into
Open
Report a malformed --account file instead of panicking#1687arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
Every value read out of the --account JSON used a bare type assertion, so
step oauth panics on the file's contents before any network call:
step oauth --account sa.json --bare
{"type":"service_account"} panic: interface conversion: interface {} is nil, not string
{"installed":{}} panic: interface conversion: interface {} is nil, not string
{"installed":"notamap"} panic: interface conversion: interface {} is string, not map[string]interface {}
Any partial, truncated, or non-Google account file does this. Without
STEPDEBUG the panic handler reports it as "Something unexpected happened"
and asks the user to mail the output in.
The unsupported-account-type branch had a separate bug: it wrapped err,
which is nil at that point, and errors.Wrapf(nil, ...) returns nil. So an
unrecognised file reported no error at all and the flow continued with empty
endpoints. Confirmed: that path printed nothing and hung.
Moved the parsing into readAccountCredentials so it can be tested without
starting an OAuth flow, and read each value with the two-value form, naming
the key that is missing or of the wrong type.
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Every value read out of the
--accountJSON uses a bare type assertion:The file is read and
json.Unmarshaled intomap[string]interface{}before any network call, so its contents alone decide whether these run. Three shapes panic:Any partial, truncated, or non-Google account file does this. Without
STEPDEBUGthe panic handler inroot.gopresents it as "Something unexpected happened" and asks the user to mail the output to info@smallstep.com, so it reads as an internal fault rather than a bad file.The
elsebranch has a separate bug:erris nil by then, anderrors.Wrapf(nil, ...)returns nil, so an unrecognised account file reported no error and execution continued with empty endpoints. I confirmed that:{"other":1}printed nothing and hung rather than failing.Each value is now read with the two-value form and names the key that is missing or of the wrong type, and the unsupported-type branch returns a real error:
I moved the block into
readAccountCredentialsso it can be tested at all.command/oauthhad no test file, and drivingoauthCmddirectly is not a viable test: it launches a browser and starts the real OAuth flow, which I do not want in your CI. The helper is a pure function of the filename, so the nine new tests cover the five error shapes, a missing file, and both well-formed shapes asserting the values and thedo2loflag. They panic without the change.A well-formed
installedfile still parses to the same endpoints and credentials as before; the refactor is meant to be behaviour-preserving apart from the error paths.