Skip to content

ads-github-show-rate-limits: http response code not checked #44

@salewski

Description

@salewski

The ads-github-show-rate-limits program is checking the exit status of the
curl subprocess, but is not arranging for the HTTP status code to be
available for consideration. This can lead to the program proceeding when it
really ought to stop, and (in at least one case) is also suppressing
information that should be displayed to the user. For example, enabling 2FA
for an account (see issue #42) but not configuring a GitHub personal access
code can cause the program to error out with the mysterious message:

    $ ads-github-show-rate-limits
    jq: error (at <stdin>:1): null (null) has no keys
    ads-github-show-rate-limits (error): was unable to extract rate limit data from GitHub service response; bailing out

Cranking up the trace output reveals that the GitHub v3 API attempted to convey
a helpful "Must specify two-factor authentication OTP code." message, but the
app did not notice so inadvertently suppressed it. The fat arrow shows where
the curl exit status is checked, and you can see that the program then
simply proceeds to feed the JSON response to jq without first checking the
HTTP response code.

    $ ads-github-show-rate-limits -vvv
    ...
    + printf 'ads-github-show-rate-limits (info): requesting /rate_limit\n'
    ads-github-show-rate-limits (info): requesting /rate_limit
    ++ /usr/bin/curl --silent --show-error --tlsv1.2 --proto https --proto-redir https --basic --netrc --user-agent ads-github-show-rate-limits --header 'Accept: application/vnd.github.v3+json' --get https://api.github.com/rate_limit
    + t_gh_json_service_response='{"message":"Must specify two-factor authentication OTP code.","documentation_url":"https://developer.github.com/v3/auth#working-with-two-factor-authentication"}'
=>  + test 0 -ne 0
    ++ echo '{"message":"Must specify two-factor authentication OTP code.","documentation_url":"https://developer.github.com/v3/auth#working-with-two-factor-authentication"}'
    ++ /usr/bin/jq -r '.resources | ( keys[] as $k | "\( $k ):\( .[$k].limit ):\( .[$k].remaining ):\( .[$k].reset )" )'
    jq: error (at <stdin>:1): null (null) has no keys
    + RATE_LIMIT_DATA_LINES=
    + test 5 -ne 0
    + printf 'ads-github-show-rate-limits (error): was unable to extract rate limit data from GitHub service response; bailing out\n'
    ads-github-show-rate-limits (error): was unable to extract rate limit data from GitHub service response; bailing out
    + exit 1
    + f_cleanup
    + test 0 -eq 0
    + return
    $ ads-github-show-rate-limits --version
    ads-github-show-rate-limits 0.2.0  (built: 2017-02-26 16:52:08)
    Copyright (C) 2016 Alan D. Salewski
    License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

    Written by Alan D. Salewski.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions