-
Notifications
You must be signed in to change notification settings - Fork 375
improving code quality of jwt module #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| def verify_claims | ||
| Verify.verify_claims(@payload, @options) | ||
| end | ||
| def options_includes_algo_in_header? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use empty lines between method definitions.
| def verify? | ||
| @verify | ||
| end | ||
| def verify_claims |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use empty lines between method definitions.
| def allowed_algorithms(options) | ||
| if options.key?(:algorithm) | ||
| [options[:algorithm]] | ||
| def allowed_algorithms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use empty lines between method definitions.
| end | ||
|
|
||
| def decode(jwt, key = nil, verify = true, custom_options = {}, &keyfinder) | ||
| def decode(jwt, key = nil, verify = true, options = {}, &keyfinder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JWT#decode has boolean parameter 'verify'
db0be71 to
847c8a3
Compare
lib/jwt/decode.rb
Outdated
| @segments.first(2).join('.') | ||
| end | ||
|
|
||
| def parse_and_decode segment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use def with parentheses when there are parameters.
lib/jwt/decode.rb
Outdated
| def validate_segment_count | ||
| raise(JWT::DecodeError, 'Not enough or too many segments') unless | ||
| (@verify and @segments.length != 3) || | ||
| (@segments.length != 3 or @segments.length != 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use || instead of or.
lib/jwt/decode.rb
Outdated
| private | ||
| def validate_segment_count | ||
| raise(JWT::DecodeError, 'Not enough or too many segments') unless | ||
| (@verify and @segments.length != 3) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use && instead of and.
lib/jwt/decode.rb
Outdated
| required_num_segments = @verify ? [3] : [2, 3] | ||
| raise(JWT::DecodeError, 'Not enough or too many segments') unless required_num_segments.include? segments.length | ||
| segments | ||
| private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless private access modifier.
lib/jwt/decode.rb
Outdated
| def validate_segment_count | ||
| raise(JWT::DecodeError, 'Not enough or too many segments') unless | ||
| (@verify and @segments.length != 3) || | ||
| (@segments.length != 3 or @segments.length != 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 4 (not 0) spaces for indenting a condition in an unless statement spanning multiple lines.
lib/jwt/decode.rb
Outdated
| rescue JSON::ParserError | ||
| raise JWT::DecodeError, 'Invalid segment encoding' | ||
| end | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra empty line detected at class body end.
lib/jwt/decode.rb
Outdated
| required_num_segments = @verify ? [3] : [2, 3] | ||
| raise(JWT::DecodeError, 'Not enough or too many segments') unless required_num_segments.include? segments.length | ||
| segments | ||
| private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep a blank line before and after private.
lib/jwt/decode.rb
Outdated
| private | ||
| def validate_segment_count | ||
| raise(JWT::DecodeError, 'Not enough or too many segments') unless | ||
| (@verify and @segments.length != 3) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JWT::Decode#validate_segment_count calls '@segments.length' 3 times
| (@verify && segment_length != 3) || | ||
| (segment_length != 3 || segment_length != 2) | ||
| end | ||
| def segment_length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use empty lines between method definitions.
|
Ebert has finished reviewing this Pull Request and has found:
You can see more details about this review at https://ebertapp.io/github/jwt/ruby-jwt/pulls/266. |
|
@excpt I am thinking about implementing DecodedToken class that will return from JWT#decode. It will act as array with two elements for backward compatability. It should also probably implement payload and header attributes to access the data directly, as well as an errors method. My issue is not sure how to implement the backwards compatibility for errors. if we return an array from #errors method on DecodedToken instead of throwing errors it will break all existing implementations, let me know. #124 |
excpt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! 🥇
|
@ab320012 The introduction of Encode/Decode value objects should happen in a different PR. Thanks for all your effort and time you invest! |
I started looking into the #errors and #value object return for decode and wanted to clean up the logic before implementing