From d162701e84c7f71689e9553c970c08bced26c2d1 Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Mon, 1 Nov 2021 00:26:40 +0700 Subject: [PATCH 01/12] =?UTF-8?q?=F0=9F=9A=A8=20Setup=20Rubocop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Minimum required lint fixes - Remainder in .rubocop_todo.yml - Closes #205 Signed-off-by: Peter Boling --- .github/workflows/style.yml | 36 + .rubocop.yml | 1177 +-------------- .rubocop_todo.yml | 1277 +++++++++++++++++ Gemfile | 2 +- Rakefile | 13 +- bin/oauth | 4 +- examples/twitter.rb | 8 +- examples/yql.rb | 8 +- lib/oauth.rb | 14 +- lib/oauth/cli.rb | 36 +- lib/oauth/cli/base_command.rb | 2 +- lib/oauth/client/action_controller_request.rb | 14 +- lib/oauth/client/em_http.rb | 18 +- lib/oauth/client/helper.rb | 44 +- lib/oauth/client/net_http.rb | 10 +- lib/oauth/consumer.rb | 42 +- lib/oauth/errors.rb | 6 +- lib/oauth/helper.rb | 8 +- lib/oauth/oauth_test_helper.rb | 8 +- .../action_controller_request.rb | 18 +- .../request_proxy/action_dispatch_request.rb | 2 +- lib/oauth/request_proxy/base.rb | 32 +- lib/oauth/request_proxy/curb_request.rb | 10 +- lib/oauth/request_proxy/em_http_request.rb | 10 +- lib/oauth/request_proxy/jabber_request.rb | 6 +- lib/oauth/request_proxy/mock_request.rb | 2 +- lib/oauth/request_proxy/net_http.rb | 18 +- lib/oauth/request_proxy/rack_request.rb | 8 +- .../request_proxy/rest_client_request.rb | 14 +- lib/oauth/request_proxy/typhoeus_request.rb | 14 +- lib/oauth/server.rb | 4 +- lib/oauth/signature/base.rb | 10 +- lib/oauth/signature/hmac/sha1.rb | 8 +- lib/oauth/signature/hmac/sha256.rb | 8 +- lib/oauth/signature/plaintext.rb | 4 +- lib/oauth/signature/rsa/sha1.rb | 6 +- lib/oauth/token.rb | 10 +- lib/oauth/tokens/access_token.rb | 6 +- oauth.gemspec | 42 +- test/cases/oauth_case.rb | 10 +- .../1_0-final/test_construct_request_url.rb | 4 +- .../test_normalize_request_parameters.rb | 16 +- .../1_0-final/test_parameter_encodings.rb | 30 +- .../1_0-final/test_signature_base_strings.rb | 61 +- test/integration/consumer_test.rb | 80 +- test/support/minitest_helpers.rb | 8 +- test/test_helper.rb | 20 +- test/units/test_access_token.rb | 2 +- .../test_action_controller_request_proxy.rb | 78 +- .../test_action_dispatch_request_proxy.rb | 38 +- test/units/test_cli.rb | 110 +- test/units/test_client_helper.rb | 36 +- test/units/test_consumer.rb | 72 +- test/units/test_curb_request_proxy.rb | 66 +- test/units/test_em_http_client.rb | 38 +- test/units/test_em_http_request_proxy.rb | 42 +- test/units/test_hmac_sha1.rb | 14 +- test/units/test_hmac_sha256.rb | 16 +- test/units/test_net_http_client.rb | 178 +-- test/units/test_net_http_request_proxy.rb | 72 +- test/units/test_oauth_helper.rb | 60 +- test/units/test_rack_request_proxy.rb | 38 +- test/units/test_request_token.rb | 2 +- test/units/test_rest_client_request_proxy.rb | 72 +- test/units/test_rsa_sha1.rb | 26 +- test/units/test_server.rb | 4 +- test/units/test_signature.rb | 6 +- test/units/test_signature_base.rb | 8 +- test/units/test_signature_hmac_sha1.rb | 48 +- test/units/test_signature_hmac_sha256.rb | 48 +- test/units/test_signature_plain_text.rb | 22 +- test/units/test_token.rb | 10 +- test/units/test_typhoeus_request_proxy.rb | 100 +- 73 files changed, 2342 insertions(+), 2052 deletions(-) create mode 100644 .github/workflows/style.yml create mode 100644 .rubocop_todo.yml diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml new file mode 100644 index 00000000..f61e5c21 --- /dev/null +++ b/.github/workflows/style.yml @@ -0,0 +1,36 @@ +name: Code Style Checks + +on: + push: + branches: + - master + - '*-maintenance' + - '*-dev' + tags: + - '!*' # Do not execute on tags + pull_request: + branches: + - '*' + +jobs: + rubocop: + name: Rubocop + if: "!contains(github.event.commits[0].message, '[ci skip]') && !contains(github.event.commits[0].message, '[skip ci]')" + strategy: + fail-fast: false + matrix: + ruby: + - 2.6 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install cURL Headers + run: sudo apt-get install libcurl4-openssl-dev + - name: Setup Ruby & Bundle + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run Rubocop + run: bundle exec rubocop -DESP \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml index 3f1d2224..55cdb79d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,1156 +1,119 @@ -AllCops: - DisabledByDefault: true - -#################### Lint ################################ - -Lint/AmbiguousOperator: - Description: >- - Checks for ambiguous operators in the first argument of a - method invocation without parentheses. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-as-args' - Enabled: true - -Lint/AmbiguousRegexpLiteral: - Description: >- - Checks for ambiguous regexp literals in the first argument of - a method invocation without parenthesis. - Enabled: true - -Lint/AssignmentInCondition: - Description: "Don't use assignment in conditions." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition' - Enabled: true - -Lint/BlockAlignment: - Description: 'Align block ends correctly.' - Enabled: true - -Lint/CircularArgumentReference: - Description: "Don't refer to the keyword argument in the default value." - Enabled: true - -Lint/ConditionPosition: - Description: >- - Checks for condition placed in a confusing position relative to - the keyword. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#same-line-condition' - Enabled: true - -Lint/Debugger: - Description: 'Check for debugger calls.' - Enabled: true - -Lint/DefEndAlignment: - Description: 'Align ends corresponding to defs correctly.' - Enabled: true - -Lint/DeprecatedClassMethods: - Description: 'Check for deprecated class method calls.' - Enabled: true - -Lint/DuplicateMethods: - Description: 'Check for duplicate methods calls.' - Enabled: true +inherit_from: .rubocop_todo.yml -Lint/EachWithObjectArgument: - Description: 'Check for immutable argument given to each_with_object.' - Enabled: true +require: + - 'rubocop-md' + - 'rubocop-minitest' + - 'rubocop-packaging' + - 'rubocop-performance' + - 'rubocop-rake' -Lint/ElseLayout: - Description: 'Check for odd code arrangement in an else block.' - Enabled: true +AllCops: + NewCops: enable + DisplayCopNames: true # Display the name of the failing cops + TargetRubyVersion: 2.6 # Oldest non-EOL Ruby -Lint/EmptyEnsure: - Description: 'Checks for empty ensure block.' +Gemspec/DateAssignment: # new in 1.10 Enabled: true - -Lint/EmptyInterpolation: - Description: 'Checks for empty string interpolation.' +Layout/DotPosition: Enabled: true - -Lint/EndAlignment: - Description: 'Align ends correctly.' + EnforcedStyle: trailing +Layout/LineEndStringConcatenationIndentation: # new in 1.18 Enabled: true - -Lint/EndInMethod: - Description: 'END blocks should not be placed inside method definitions.' +Layout/SpaceBeforeBrackets: # new in 1.7 Enabled: true - -Lint/EnsureReturn: - Description: 'Do not use return in an ensure block.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-return-ensure' +Lint/AmbiguousAssignment: # new in 1.7 Enabled: true - -Lint/Eval: - Description: 'The use of eval represents a serious security risk.' +Lint/AmbiguousOperatorPrecedence: # new in 1.21 Enabled: true - -Lint/FormatParameterMismatch: - Description: 'The number of parameters to format/sprint must match the fields.' +Lint/AmbiguousRange: # new in 1.19 Enabled: true - -Lint/HandleExceptions: - Description: "Don't suppress exception." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions' +Lint/DeprecatedConstants: # new in 1.8 Enabled: true - -Lint/InvalidCharacterLiteral: - Description: >- - Checks for invalid character literals with a non-escaped - whitespace character. +Lint/DuplicateBranch: # new in 1.3 Enabled: true - -Lint/LiteralInCondition: - Description: 'Checks of literals used in conditions.' +Lint/DuplicateRegexpCharacterClassElement: # new in 1.1 Enabled: true - -Lint/LiteralInInterpolation: - Description: 'Checks for literals used in interpolation.' +Lint/EmptyBlock: # new in 1.1 Enabled: true - -Lint/Loop: - Description: >- - Use Kernel#loop with break rather than begin/end/until or - begin/end/while for post-loop tests. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#loop-with-break' +Lint/EmptyClass: # new in 1.3 Enabled: true - -Lint/NestedMethodDefinition: - Description: 'Do not use nested method definitions.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-methods' +Lint/EmptyInPattern: # new in 1.16 Enabled: true - -Lint/NonLocalExitFromIterator: - Description: 'Do not use return in iterator to cause non-local exit.' +Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21 Enabled: true - -Lint/ParenthesesAsGroupedExpression: - Description: >- - Checks for method calls with a space before the opening - parenthesis. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces' +Lint/LambdaWithoutLiteralBlock: # new in 1.8 Enabled: true - -Lint/RequireParentheses: - Description: >- - Use parentheses in the method call to avoid confusion - about precedence. +Lint/NoReturnInBeginEndBlocks: # new in 1.2 Enabled: true - -Lint/RescueException: - Description: 'Avoid rescuing the Exception class.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-blind-rescues' +Lint/NumberedParameterAssignment: # new in 1.9 Enabled: true - -Lint/ShadowingOuterLocalVariable: - Description: >- - Do not use the same name as outer local variable - for block arguments or block local variables. +Lint/OrAssignmentToConstant: # new in 1.9 Enabled: true - -Lint/StringConversionInInterpolation: - Description: 'Checks for Object#to_s usage in string interpolation.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-to-s' +Lint/RedundantDirGlobSort: # new in 1.8 Enabled: true - -Lint/UnderscorePrefixedVariableName: - Description: 'Do not use prefix `_` for a variable that is used.' +Lint/RequireRelativeSelfPath: # new in 1.22 Enabled: true - -Lint/UnneededDisable: - Description: >- - Checks for rubocop:disable comments that can be removed. - Note: this cop is not disabled when disabling all cops. - It must be explicitly disabled. +Lint/SymbolConversion: # new in 1.9 Enabled: true - -Lint/UnusedBlockArgument: - Description: 'Checks for unused block arguments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars' +Lint/ToEnumArguments: # new in 1.1 Enabled: true - -Lint/UnusedMethodArgument: - Description: 'Checks for unused method arguments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars' +Lint/TripleQuotes: # new in 1.9 Enabled: true - -Lint/UnreachableCode: - Description: 'Unreachable code.' +Lint/UnexpectedBlockArity: # new in 1.5 Enabled: true - -Lint/UselessAccessModifier: - Description: 'Checks for useless access modifiers.' +Lint/UnmodifiedReduceAccumulator: # new in 1.1 Enabled: true - -Lint/UselessAssignment: - Description: 'Checks for useless assignment to a local variable.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars' +Metrics/BlockLength: + IgnoredMethods: + - context + - describe + - it + - shared_context + - shared_examples + - shared_examples_for +Security/IoMethods: # new in 1.22 Enabled: true - -Lint/UselessComparison: - Description: 'Checks for comparison of something with itself.' +Style/ArgumentsForwarding: # new in 1.1 Enabled: true - -Lint/UselessElseWithoutRescue: - Description: 'Checks for useless `else` in `begin..end` without `rescue`.' +Style/CollectionCompact: # new in 1.2 Enabled: true - -Lint/UselessSetterCall: - Description: 'Checks for useless setter call to a local variable.' +Style/DocumentDynamicEvalDefinition: # new in 1.1 Enabled: true - -Lint/Void: - Description: 'Possible use of operator/literal/variable in void context.' +Style/EndlessMethod: # new in 1.8 Enabled: true - -###################### Metrics #################################### - -Metrics/AbcSize: - Description: >- - A calculated magnitude based on number of assignments, - branches, and conditions. - Reference: 'http://c2.com/cgi/wiki?AbcMetric' - Enabled: false - Max: 20 - -Metrics/BlockNesting: - Description: 'Avoid excessive block nesting' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count' +Style/HashConversion: # new in 1.10 Enabled: true - Max: 4 - -Metrics/ClassLength: - Description: 'Avoid classes longer than 250 lines of code.' +Style/HashExcept: # new in 1.7 Enabled: true - Max: 250 - -Metrics/CyclomaticComplexity: - Description: >- - A complexity metric that is strongly correlated to the number - of test cases needed to validate a method. +Style/IfWithBooleanLiteralBranches: # new in 1.9 Enabled: true - -Metrics/LineLength: - Description: 'Limit lines to 80 characters.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits' - Enabled: false - -Metrics/MethodLength: - Description: 'Avoid methods longer than 30 lines of code.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#short-methods' +Style/InPatternThen: # new in 1.16 Enabled: true - Max: 30 - -Metrics/ModuleLength: - Description: 'Avoid modules longer than 250 lines of code.' +Style/MultilineInPatternThen: # new in 1.16 Enabled: true - Max: 250 - -Metrics/ParameterLists: - Description: 'Avoid parameter lists longer than three or four parameters.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#too-many-params' +Style/NegatedIfElseCondition: # new in 1.2 Enabled: true - -Metrics/PerceivedComplexity: - Description: >- - A complexity metric geared towards measuring complexity for a - human reader. - Enabled: false - -##################### Performance ############################# - -Performance/Count: - Description: >- - Use `count` instead of `select...size`, `reject...size`, - `select...count`, `reject...count`, `select...length`, - and `reject...length`. +Style/NilLambda: # new in 1.3 Enabled: true - -Performance/Detect: - Description: >- - Use `detect` instead of `select.first`, `find_all.first`, - `select.last`, and `find_all.last`. - Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerabledetect-vs-enumerableselectfirst-code' +Style/NumberedParameters: # new in 1.22 Enabled: true - -Performance/FlatMap: - Description: >- - Use `Enumerable#flat_map` - instead of `Enumerable#map...Array#flatten(1)` - or `Enumberable#collect..Array#flatten(1)` - Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablemaparrayflatten-vs-enumerableflat_map-code' +Style/NumberedParametersLimit: # new in 1.22 Enabled: true - EnabledForFlattenWithoutParams: false - # If enabled, this cop will warn about usages of - # `flatten` being called without any parameters. - # This can be dangerous since `flat_map` will only flatten 1 level, and - # `flatten` without any parameters can flatten multiple levels. - -Performance/ReverseEach: - Description: 'Use `reverse_each` instead of `reverse.each`.' - Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablereverseeach-vs-enumerablereverse_each-code' +Style/QuotedSymbols: # new in 1.16 Enabled: true - -Performance/Sample: - Description: >- - Use `sample` instead of `shuffle.first`, - `shuffle.last`, and `shuffle[Fixnum]`. - Reference: 'https://github.com/JuanitoFatas/fast-ruby#arrayshufflefirst-vs-arraysample-code' +Style/RedundantArgument: # new in 1.4 Enabled: true - -Performance/Size: - Description: >- - Use `size` instead of `count` for counting - the number of elements in `Array` and `Hash`. - Reference: 'https://github.com/JuanitoFatas/fast-ruby#arraycount-vs-arraysize-code' +Style/RedundantSelfAssignmentBranch: # new in 1.19 Enabled: true - -Performance/StringReplacement: - Description: >- - Use `tr` instead of `gsub` when you are replacing the same - number of characters. Use `delete` instead of `gsub` when - you are deleting characters. - Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringgsub-vs-stringtr-code' +Style/SelectByRegexp: # new in 1.22 Enabled: true - -##################### Rails ################################## - -Rails/ActionFilter: - Description: 'Enforces consistent use of action filter methods.' - Enabled: false - -Rails/Date: - Description: >- - Checks the correct usage of date aware methods, - such as Date.today, Date.current etc. - Enabled: false - -Rails/Delegate: - Description: 'Prefer delegate method for delegations.' - Enabled: false - -Rails/FindBy: - Description: 'Prefer find_by over where.first.' - Enabled: false - -Rails/FindEach: - Description: 'Prefer all.find_each over all.find.' - Enabled: false - -Rails/HasAndBelongsToMany: - Description: 'Prefer has_many :through to has_and_belongs_to_many.' - Enabled: false - -Rails/Output: - Description: 'Checks for calls to puts, print, etc.' - Enabled: false - -Rails/ReadWriteAttribute: - Description: >- - Checks for read_attribute(:attr) and - write_attribute(:attr, val). - Enabled: false - -Rails/ScopeArgs: - Description: 'Checks the arguments of ActiveRecord scopes.' - Enabled: false - -Rails/TimeZone: - Description: 'Checks the correct usage of time zone aware methods.' - StyleGuide: 'https://github.com/bbatsov/rails-style-guide#time' - Reference: 'http://danilenko.org/2012/7/6/rails_timezones' - Enabled: false - -Rails/Validation: - Description: 'Use validates :attribute, hash of validations.' - Enabled: false - -################## Style ################################# - -Style/AccessModifierIndentation: - Description: Check indentation of private/protected visibility modifiers. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#indent-public-private-protected' - Enabled: false - -Style/AccessorMethodName: - Description: Check the naming of accessor methods for get_/set_. - Enabled: false - -Style/Alias: - Description: 'Use alias_method instead of alias.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#alias-method' - Enabled: false - -Style/AlignArray: - Description: >- - Align the elements of an array literal if they span more than - one line. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#align-multiline-arrays' - Enabled: false - -Style/AlignHash: - Description: >- - Align the elements of a hash literal if they span more than - one line. - Enabled: false - -Style/AlignParameters: - Description: >- - Align the parameters of a method call if they span more - than one line. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-double-indent' - Enabled: false - -Style/AndOr: - Description: 'Use &&/|| instead of and/or.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-and-or-or' - Enabled: false - -Style/ArrayJoin: - Description: 'Use Array#join instead of Array#*.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#array-join' - Enabled: false - -Style/AsciiComments: - Description: 'Use only ascii symbols in comments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-comments' - Enabled: false - -Style/AsciiIdentifiers: - Description: 'Use only ascii symbols in identifiers.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-identifiers' - Enabled: false - -Style/Attr: - Description: 'Checks for uses of Module#attr.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#attr' - Enabled: false - -Style/BeginBlock: - Description: 'Avoid the use of BEGIN blocks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-BEGIN-blocks' - Enabled: false - -Style/BarePercentLiterals: - Description: 'Checks if usage of %() or %Q() matches configuration.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-q-shorthand' - Enabled: false - -Style/BlockComments: - Description: 'Do not use block comments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-block-comments' - Enabled: false - -Style/BlockEndNewline: - Description: 'Put end statement of multiline block on its own line.' - Enabled: false - -Style/BlockDelimiters: - Description: >- - Avoid using {...} for multi-line blocks (multiline chaining is - always ugly). - Prefer {...} over do...end for single-line blocks. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks' - Enabled: false - -Style/BracesAroundHashParameters: - Description: 'Enforce braces style around hash parameters.' - Enabled: false - -Style/CaseEquality: - Description: 'Avoid explicit use of the case equality operator(===).' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-case-equality' - Enabled: false - -Style/CaseIndentation: - Description: 'Indentation of when in a case/when/[else/]end.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#indent-when-to-case' - Enabled: false - -Style/CharacterLiteral: - Description: 'Checks for uses of character literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-character-literals' - Enabled: false - -Style/ClassAndModuleCamelCase: - Description: 'Use CamelCase for classes and modules.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#camelcase-classes' - Enabled: false - -Style/ClassAndModuleChildren: - Description: 'Checks style of children classes and modules.' - Enabled: false - -Style/ClassCheck: - Description: 'Enforces consistent use of `Object#is_a?` or `Object#kind_of?`.' - Enabled: false - -Style/ClassMethods: - Description: 'Use self when defining module/class methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#def-self-class-methods' - Enabled: false - -Style/ClassVars: - Description: 'Avoid the use of class variables.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-class-vars' - Enabled: false - -Style/ClosingParenthesisIndentation: - Description: 'Checks the indentation of hanging closing parentheses.' - Enabled: false - -Style/ColonMethodCall: - Description: 'Do not use :: for method call.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#double-colons' - Enabled: false - -Style/CommandLiteral: - Description: 'Use `` or %x around command literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-x' - Enabled: false - -Style/CommentAnnotation: - Description: 'Checks formatting of annotation comments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#annotate-keywords' - Enabled: false - -Style/CommentIndentation: - Description: 'Indentation of comments.' - Enabled: false - -Style/ConstantName: - Description: 'Constants should use SCREAMING_SNAKE_CASE.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#screaming-snake-case' - Enabled: false - -Style/DefWithParentheses: - Description: 'Use def with parentheses when there are arguments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens' - Enabled: false - -Style/DeprecatedHashMethods: - Description: 'Checks for use of deprecated Hash methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-key' - Enabled: false - -Style/Documentation: - Description: 'Document classes and non-namespace modules.' - Enabled: false - -Style/DotPosition: - Description: 'Checks the position of the dot in multi-line method calls.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains' - Enabled: false - -Style/DoubleNegation: - Description: 'Checks for uses of double negation (!!).' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-bang-bang' - Enabled: false - -Style/EachWithObject: - Description: 'Prefer `each_with_object` over `inject` or `reduce`.' - Enabled: false - -Style/ElseAlignment: - Description: 'Align elses and elsifs correctly.' - Enabled: false - -Style/EmptyElse: - Description: 'Avoid empty else-clauses.' - Enabled: false - -Style/EmptyLineBetweenDefs: - Description: 'Use empty lines between defs.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#empty-lines-between-methods' - Enabled: false - -Style/EmptyLines: - Description: "Don't use several empty lines in a row." - Enabled: false - -Style/EmptyLinesAroundAccessModifier: - Description: "Keep blank lines around access modifiers." - Enabled: false - -Style/EmptyLinesAroundBlockBody: - Description: "Keeps track of empty lines around block bodies." - Enabled: false - -Style/EmptyLinesAroundClassBody: - Description: "Keeps track of empty lines around class bodies." - Enabled: false - -Style/EmptyLinesAroundModuleBody: - Description: "Keeps track of empty lines around module bodies." - Enabled: false - -Style/EmptyLinesAroundMethodBody: - Description: "Keeps track of empty lines around method bodies." - Enabled: false - -Style/EmptyLiteral: - Description: 'Prefer literals to Array.new/Hash.new/String.new.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#literal-array-hash' - Enabled: false - -Style/EndBlock: - Description: 'Avoid the use of END blocks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-END-blocks' - Enabled: false - -Style/EndOfLine: - Description: 'Use Unix-style line endings.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#crlf' - Enabled: false - -Style/EvenOdd: - Description: 'Favor the use of Fixnum#even? && Fixnum#odd?' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods' - Enabled: false - -Style/ExtraSpacing: - Description: 'Do not use unnecessary spacing.' - Enabled: false - -Style/FileName: - Description: 'Use snake_case for source file names.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-files' - Enabled: false - -Style/InitialIndentation: - Description: >- - Checks the indentation of the first non-blank non-comment line in a file. - Enabled: false - -Style/FirstParameterIndentation: - Description: 'Checks the indentation of the first parameter in a method call.' - Enabled: false - -Style/FlipFlop: - Description: 'Checks for flip flops' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-flip-flops' - Enabled: false - -Style/For: - Description: 'Checks use of for or each in multiline loops.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-for-loops' - Enabled: false - -Style/FormatString: - Description: 'Enforce the use of Kernel#sprintf, Kernel#format or String#%.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#sprintf' - Enabled: false - -Style/GlobalVars: - Description: 'Do not introduce global variables.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#instance-vars' - Reference: 'http://www.zenspider.com/Languages/Ruby/QuickRef.html' - Enabled: false - -Style/GuardClause: - Description: 'Check for conditionals that can be replaced with guard clauses' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals' - Enabled: false - -Style/HashSyntax: - Description: >- - Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax - { :a => 1, :b => 2 }. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-literals' - Enabled: false - -Style/IfUnlessModifier: - Description: >- - Favor modifier if/unless usage when you have a - single-line body. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier' - Enabled: false - -Style/IfWithSemicolon: - Description: 'Do not use if x; .... Use the ternary operator instead.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-semicolon-ifs' - Enabled: false - -Style/IndentationConsistency: - Description: 'Keep indentation straight.' - Enabled: false - -Style/IndentationWidth: - Description: 'Use 2 spaces for indentation.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation' - Enabled: false - -Style/IndentArray: - Description: >- - Checks the indentation of the first element in an array - literal. - Enabled: false - -Style/IndentHash: - Description: 'Checks the indentation of the first key in a hash literal.' - Enabled: false - -Style/InfiniteLoop: - Description: 'Use Kernel#loop for infinite loops.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#infinite-loop' - Enabled: false - -Style/Lambda: - Description: 'Use the new lambda literal syntax for single-line blocks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#lambda-multi-line' - Enabled: false - -Style/LambdaCall: - Description: 'Use lambda.call(...) instead of lambda.(...).' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#proc-call' - Enabled: false - -Style/LeadingCommentSpace: - Description: 'Comments should start with a space.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space' - Enabled: false - -Style/LineEndConcatenation: - Description: >- - Use \ instead of + or << to concatenate two string literals at - line end. - Enabled: false - -Style/MethodCallParentheses: - Description: 'Do not use parentheses for method calls with no arguments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens' - Enabled: false - -Style/MethodDefParentheses: - Description: >- - Checks if the method definitions have or don't have - parentheses. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens' - Enabled: false - -Style/MethodName: - Description: 'Use the configured style when naming methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars' - Enabled: false - -Style/ModuleFunction: - Description: 'Checks for usage of `extend self` in modules.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#module-function' - Enabled: false - -Style/MultilineBlockChain: - Description: 'Avoid multi-line chains of blocks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks' - Enabled: false - -Style/MultilineBlockLayout: - Description: 'Ensures newlines after multiline block do statements.' - Enabled: false - -Style/MultilineIfThen: - Description: 'Do not use then for multi-line if/unless.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-then' - Enabled: false - -Style/MultilineOperationIndentation: - Description: >- - Checks indentation of binary operations that span more than - one line. - Enabled: false - -Style/MultilineTernaryOperator: - Description: >- - Avoid multi-line ?: (the ternary operator); - use if/unless instead. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-multiline-ternary' - Enabled: false - -Style/NegatedIf: - Description: >- - Favor unless over if for negative conditions - (or control flow or). - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#unless-for-negatives' - Enabled: false - -Style/NegatedWhile: - Description: 'Favor until over while for negative conditions.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#until-for-negatives' - Enabled: false - -Style/NestedTernaryOperator: - Description: 'Use one expression per branch in a ternary operator.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-ternary' - Enabled: false - -Style/Next: - Description: 'Use `next` to skip iteration instead of a condition at the end.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals' - Enabled: false - -Style/NilComparison: - Description: 'Prefer x.nil? to x == nil.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods' - Enabled: false - -Style/NonNilCheck: - Description: 'Checks for redundant nil checks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-non-nil-checks' - Enabled: false - -Style/Not: - Description: 'Use ! instead of not.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#bang-not-not' - Enabled: false - -Style/NumericLiterals: - Description: >- - Add underscores to large numeric literals to improve their - readability. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscores-in-numerics' - Enabled: false - -Style/OneLineConditional: - Description: >- - Favor the ternary operator(?:) over - if/then/else/end constructs. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#ternary-operator' - Enabled: false - -Style/OpMethod: - Description: 'When defining binary operators, name the argument other.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#other-arg' - Enabled: false - -Style/OptionalArguments: - Description: >- - Checks for optional arguments that do not appear at the end - of the argument list - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#optional-arguments' - Enabled: false - -Style/ParallelAssignment: - Description: >- - Check for simple usages of parallel assignment. - It will only warn when the number of variables - matches on both sides of the assignment. - This also provides performance benefits - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parallel-assignment' - Enabled: false - -Style/ParenthesesAroundCondition: - Description: >- - Don't use parentheses around the condition of an - if/unless/while. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-parens-if' - Enabled: false - -Style/PercentLiteralDelimiters: - Description: 'Use `%`-literal delimiters consistently' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-literal-braces' - Enabled: false - -Style/PercentQLiterals: - Description: 'Checks if uses of %Q/%q match the configured preference.' - Enabled: false - -Style/PerlBackrefs: - Description: 'Avoid Perl-style regex back references.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers' - Enabled: false - -Style/PredicateName: - Description: 'Check the names of predicate methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark' - Enabled: false - -Style/Proc: - Description: 'Use proc instead of Proc.new.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#proc' - Enabled: false - -Style/RaiseArgs: - Description: 'Checks the arguments passed to raise/fail.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#exception-class-messages' - Enabled: false - -Style/RedundantBegin: - Description: "Don't use begin blocks when they are not needed." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#begin-implicit' - Enabled: false - -Style/RedundantException: - Description: "Checks for an obsolete RuntimeException argument in raise/fail." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-explicit-runtimeerror' - Enabled: false - -Style/RedundantReturn: - Description: "Don't use return where it's not required." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-explicit-return' - Enabled: false - -Style/RedundantSelf: - Description: "Don't use self where it's not needed." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-self-unless-required' - Enabled: false - -Style/RegexpLiteral: - Description: 'Use / or %r around regular expressions.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-r' - Enabled: false - -Style/RescueEnsureAlignment: - Description: 'Align rescues and ensures correctly.' - Enabled: false - -Style/RescueModifier: - Description: 'Avoid using rescue in its modifier form.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers' - Enabled: false - -Style/SelfAssignment: - Description: >- - Checks for places where self-assignment shorthand should have - been used. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#self-assignment' - Enabled: false - -Style/Semicolon: - Description: "Don't use semicolons to terminate expressions." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-semicolon' - Enabled: false - -Style/SignalException: - Description: 'Checks for proper usage of fail and raise.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#fail-method' - Enabled: false - -Style/SingleLineBlockParams: - Description: 'Enforces the names of some block params.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#reduce-blocks' - Enabled: false - -Style/SingleLineMethods: - Description: 'Avoid single-line methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-single-line-methods' - Enabled: false - -Style/SpaceBeforeFirstArg: - Description: >- - Checks that exactly one space is used between a method name - and the first argument for method calls without parentheses. +Style/StringChars: # new in 1.12 Enabled: true - -Style/SpaceAfterColon: - Description: 'Use spaces after colons.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceAfterComma: - Description: 'Use spaces after commas.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceAroundKeyword: - Description: 'Use spaces around keywords.' - Enabled: false - -Style/SpaceAfterMethodName: - Description: >- - Do not put a space between a method name and the opening - parenthesis in a method definition. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces' - Enabled: false - -Style/SpaceAfterNot: - Description: Tracks redundant space after the ! operator. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-space-bang' - Enabled: false - -Style/SpaceAfterSemicolon: - Description: 'Use spaces after semicolons.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceBeforeBlockBraces: - Description: >- - Checks that the left block brace has or doesn't have space - before it. - Enabled: false - -Style/SpaceBeforeComma: - Description: 'No spaces before commas.' - Enabled: false - -Style/SpaceBeforeComment: - Description: >- - Checks for missing space between code and a comment on the - same line. - Enabled: false - -Style/SpaceBeforeSemicolon: - Description: 'No spaces before semicolons.' - Enabled: false - -Style/SpaceInsideBlockBraces: - Description: >- - Checks that block braces have or don't have surrounding space. - For blocks taking parameters, checks that the left brace has - or doesn't have trailing space. - Enabled: false - -Style/SpaceAroundBlockParameters: - Description: 'Checks the spacing inside and after block parameters pipes.' - Enabled: false - -Style/SpaceAroundEqualsInParameterDefault: - Description: >- - Checks that the equals signs in parameter default assignments - have or don't have surrounding space depending on - configuration. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-around-equals' - Enabled: false - -Style/SpaceAroundOperators: - Description: 'Use a single space around operators.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceInsideBrackets: - Description: 'No spaces after [ or before ].' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces' - Enabled: false - -Style/SpaceInsideHashLiteralBraces: - Description: "Use spaces inside hash literal braces - or don't." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceInsideParens: - Description: 'No spaces after ( or before ).' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces' - Enabled: false - -Style/SpaceInsideRangeLiteral: - Description: 'No spaces inside range literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-space-inside-range-literals' - Enabled: false - -Style/SpaceInsideStringInterpolation: - Description: 'Checks for padding/surrounding spaces inside string interpolation.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#string-interpolation' - Enabled: false - -Style/SpecialGlobalVars: - Description: 'Avoid Perl-style global variables.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms' - Enabled: false - Style/StringLiterals: - Description: 'Checks if uses of quotes match the configured preference.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-string-literals' - Enabled: false - + Enabled: true + EnforcedStyle: double_quotes Style/StringLiteralsInInterpolation: - Description: >- - Checks if uses of quotes inside expressions in interpolated - strings match the configured preference. - Enabled: false - -Style/StructInheritance: - Description: 'Checks for inheritance from Struct.new.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-extend-struct-new' - Enabled: false - -Style/SymbolLiteral: - Description: 'Use plain symbols instead of string symbols when possible.' - Enabled: false - -Style/SymbolProc: - Description: 'Use symbols as procs instead of blocks when possible.' - Enabled: false - -Style/Tab: - Description: 'No hard tabs.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation' - Enabled: false - -Style/TrailingBlankLines: - Description: 'Checks trailing blank lines and final newline.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#newline-eof' - Enabled: false - -Style/TrailingCommaInArguments: - Description: 'Checks for trailing comma in parameter lists.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-params-comma' - Enabled: false - -Style/TrailingCommaInLiteral: - Description: 'Checks for trailing comma in literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas' - Enabled: false - -Style/TrailingWhitespace: - Description: 'Avoid trailing whitespace.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-whitespace' - Enabled: false - -Style/TrivialAccessors: - Description: 'Prefer attr_* methods to trivial readers/writers.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#attr_family' - Enabled: false - -Style/UnlessElse: - Description: >- - Do not use unless with else. Rewrite these with the positive - case first. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-else-with-unless' - Enabled: false - -Style/UnneededCapitalW: - Description: 'Checks for %W when interpolation is not needed.' - Enabled: false - -Style/UnneededPercentQ: - Description: 'Checks for %q/%Q when single quotes or double quotes would do.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-q' - Enabled: false - -Style/TrailingUnderscoreVariable: - Description: >- - Checks for the usage of unneeded trailing underscores at the - end of parallel variable assignment. - Enabled: false - -Style/VariableInterpolation: - Description: >- - Don't interpolate global, instance and class variables - directly in strings. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#curlies-interpolate' - Enabled: false - -Style/VariableName: - Description: 'Use the configured style when naming variables.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars' - Enabled: false - -Style/WhenThen: - Description: 'Use when x then ... for one-line cases.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#one-line-cases' - Enabled: false - -Style/WhileUntilDo: - Description: 'Checks for redundant do after while or until.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-multiline-while-do' - Enabled: false - -Style/WhileUntilModifier: - Description: >- - Favor modifier while/until usage when you have a - single-line body. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#while-as-a-modifier' - Enabled: false - -Style/WordArray: - Description: 'Use %w or %W for arrays of words.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-w' - Enabled: false + Enabled: true + EnforcedStyle: double_quotes +Style/SwapValues: # new in 1.1 + Enabled: true \ No newline at end of file diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..13369309 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,1277 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2021-10-31 17:21:56 UTC using RuboCop version 1.22.3. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'oauth.gemspec' + +# Offense count: 1 +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RubyVersionGlobalsUsage: + Exclude: + - 'oauth.gemspec' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: outdent, indent +Layout/AccessModifierIndentation: + Exclude: + - 'lib/oauth/client/net_http.rb' + - 'lib/oauth/request_proxy/action_controller_request.rb' + - 'lib/oauth/request_proxy/base.rb' + - 'lib/oauth/request_proxy/net_http.rb' + - 'lib/oauth/request_proxy/rack_request.rb' + - 'lib/oauth/request_proxy/rest_client_request.rb' + - 'lib/oauth/tokens/request_token.rb' + - 'test/cases/spec/1_0-final/test_parameter_encodings.rb' + +# Offense count: 16 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_argument, with_fixed_indentation +Layout/ArgumentAlignment: + Exclude: + - 'lib/oauth/consumer.rb' + - 'lib/oauth/server.rb' + - 'test/units/test_em_http_request_proxy.rb' + - 'test/units/test_rest_client_request_proxy.rb' + - 'test/units/test_signature.rb' + - 'test/units/test_typhoeus_request_proxy.rb' + +# Offense count: 26 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_element, with_fixed_indentation +Layout/ArrayAlignment: + Exclude: + - 'lib/oauth/oauth.rb' + - 'test/units/test_cli.rb' + - 'test/units/test_oauth_helper.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Layout/ClosingHeredocIndentation: + Exclude: + - 'test/units/test_cli.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +Layout/CommentIndentation: + Exclude: + - '**/*.md' + - '**/*.markdown' + - 'test/integration/consumer_test.rb' + - 'test/units/test_net_http_client.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Layout/ConditionPosition: + Exclude: + - 'lib/oauth/request_proxy/action_controller_request.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/ElseAlignment: + Exclude: + - 'lib/oauth/client/em_http.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +Layout/EmptyLineAfterGuardClause: + Exclude: + - 'lib/oauth/consumer.rb' + - 'lib/oauth/request_proxy.rb' + - 'lib/oauth/request_proxy/jabber_request.rb' + - 'lib/oauth/request_proxy/net_http.rb' + - 'lib/oauth/signature.rb' + - 'lib/oauth/signature/base.rb' + - 'test/cases/oauth_case.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, AllowAdjacentOneLineDefs, NumberOfEmptyLines. +Layout/EmptyLineBetweenDefs: + Exclude: + - '**/*.md' + - '**/*.markdown' + - 'lib/oauth/cli/authorize_command.rb' + - 'test/cases/spec/1_0-final/test_normalize_request_parameters.rb' + - 'test/cases/spec/1_0-final/test_signature_base_strings.rb' + - 'test/integration/consumer_test.rb' + - 'test/units/test_net_http_client.rb' + +# Offense count: 20 +# Cop supports --auto-correct. +Layout/EmptyLines: + Exclude: + - 'lib/oauth/cli/authorize_command.rb' + - 'lib/oauth/consumer.rb' + - 'test/cases/oauth_case.rb' + - 'test/cases/spec/1_0-final/test_construct_request_url.rb' + - 'test/cases/spec/1_0-final/test_normalize_request_parameters.rb' + - 'test/cases/spec/1_0-final/test_signature_base_strings.rb' + - 'test/integration/consumer_test.rb' + - 'test/units/test_cli.rb' + - 'test/units/test_curb_request_proxy.rb' + - 'test/units/test_net_http_client.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowAliasSyntax, AllowedMethods. +# AllowedMethods: alias_method, public, protected, private +Layout/EmptyLinesAroundAttributeAccessor: + Exclude: + - 'lib/oauth/errors/problem.rb' + - 'lib/oauth/errors/unauthorized.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Layout/EmptyLinesAroundBeginBody: + Exclude: + - 'test/units/test_curb_request_proxy.rb' + - 'test/units/test_em_http_client.rb' + - 'test/units/test_em_http_request_proxy.rb' + - 'test/units/test_typhoeus_request_proxy.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, no_empty_lines +Layout/EmptyLinesAroundBlockBody: + Exclude: + - 'test/units/test_cli.rb' + +# Offense count: 42 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only +Layout/EmptyLinesAroundClassBody: + Enabled: false + +# Offense count: 4 +# Cop supports --auto-correct. +Layout/EmptyLinesAroundExceptionHandlingKeywords: + Exclude: + - 'test/units/test_curb_request_proxy.rb' + - 'test/units/test_em_http_client.rb' + - 'test/units/test_em_http_request_proxy.rb' + - 'test/units/test_typhoeus_request_proxy.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Layout/EmptyLinesAroundMethodBody: + Exclude: + - 'lib/oauth/consumer.rb' + - 'test/cases/spec/1_0-final/test_normalize_request_parameters.rb' + - 'test/units/test_cli.rb' + - 'test/units/test_rsa_sha1.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleAlignWith, Severity. +# SupportedStylesAlignWith: keyword, variable, start_of_line +Layout/EndAlignment: + Exclude: + - 'lib/oauth/client/em_http.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. +Layout/ExtraSpacing: + Exclude: + - 'lib/oauth/consumer.rb' + - 'oauth.gemspec' + - 'test/integration/consumer_test.rb' + - 'test/units/test_cli.rb' + - 'test/units/test_consumer.rb' + +# Offense count: 13 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses +Layout/FirstArgumentIndentation: + Exclude: + - 'lib/oauth/cli/sign_command.rb' + - 'test/integration/consumer_test.rb' + - 'test/units/test_client_helper.rb' + - 'test/units/test_consumer.rb' + - 'test/units/test_net_http_client.rb' + +# Offense count: 35 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_braces +Layout/FirstHashElementIndentation: + Exclude: + - 'test/integration/consumer_test.rb' + - 'test/units/test_client_helper.rb' + - 'test/units/test_consumer.rb' + - 'test/units/test_em_http_client.rb' + - 'test/units/test_net_http_client.rb' + +# Offense count: 193 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Layout/HashAlignment: + Enabled: false + +# Offense count: 5 +# Cop supports --auto-correct. +Layout/HeredocIndentation: + Exclude: + - 'test/units/test_cli.rb' + +# Offense count: 16 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: normal, indented_internal_methods +Layout/IndentationConsistency: + Exclude: + - 'lib/oauth/request_proxy/curb_request.rb' + - 'lib/oauth/request_proxy/rest_client_request.rb' + - 'test/units/test_net_http_client.rb' + - 'test/units/test_request_token.rb' + +# Offense count: 19 +# Cop supports --auto-correct. +# Configuration parameters: Width, IgnoredPatterns. +Layout/IndentationWidth: + Exclude: + - 'lib/oauth/client/em_http.rb' + - 'lib/oauth/consumer.rb' + - 'lib/oauth/request_proxy/rest_client_request.rb' + - 'test/units/test_consumer.rb' + - 'test/units/test_curb_request_proxy.rb' + - 'test/units/test_em_http_client.rb' + - 'test/units/test_em_http_request_proxy.rb' + - 'test/units/test_net_http_client.rb' + - 'test/units/test_request_token.rb' + - 'test/units/test_rest_client_request_proxy.rb' + - 'test/units/test_typhoeus_request_proxy.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/InitialIndentation: + Exclude: + - 'lib/oauth/request_proxy/curb_request.rb' + +# Offense count: 11 +# Cop supports --auto-correct. +# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. +Layout/LeadingCommentSpace: + Exclude: + - '**/*.md' + - '**/*.markdown' + - 'lib/oauth/helper.rb' + - 'lib/oauth/request_proxy.rb' + - 'oauth.gemspec' + - 'test/cases/spec/1_0-final/test_construct_request_url.rb' + - 'test/units/test_request_token.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineArrayBraceLayout: + Exclude: + - 'test/units/test_cli.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineHashBraceLayout: + Exclude: + - 'lib/oauth/client/helper.rb' + +# Offense count: 22 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineMethodCallBraceLayout: + Exclude: + - 'test/integration/consumer_test.rb' + - 'test/units/test_client_helper.rb' + - 'test/units/test_consumer.rb' + - 'test/units/test_net_http_client.rb' + - 'test/units/test_request_token.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented +Layout/MultilineOperationIndentation: + Exclude: + - 'lib/oauth/consumer.rb' + +# Offense count: 202 +# Cop supports --auto-correct. +Layout/SpaceAfterComma: + Enabled: false + +# Offense count: 22 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: space, no_space +Layout/SpaceAroundEqualsInParameterDefault: + Exclude: + - 'lib/oauth/cli/base_command.rb' + - 'lib/oauth/client/action_controller_request.rb' + - 'lib/oauth/helper.rb' + - 'lib/oauth/tokens/consumer_token.rb' + - 'test/cases/oauth_case.rb' + - 'test/cases/spec/1_0-final/test_construct_request_url.rb' + - 'test/cases/spec/1_0-final/test_normalize_request_parameters.rb' + - 'test/cases/spec/1_0-final/test_signature_base_strings.rb' + - 'test/units/test_cli.rb' + - 'test/units/test_consumer.rb' + +# Offense count: 229 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. +# SupportedStylesForExponentOperator: space, no_space +Layout/SpaceAroundOperators: + Exclude: + - 'lib/oauth/consumer.rb' + - 'lib/oauth/request_proxy/base.rb' + - 'oauth.gemspec' + - 'test/cases/oauth_case.rb' + - 'test/cases/spec/1_0-final/test_normalize_request_parameters.rb' + - 'test/cases/spec/1_0-final/test_signature_base_strings.rb' + - 'test/integration/consumer_test.rb' + - 'test/units/test_action_controller_request_proxy.rb' + - 'test/units/test_cli.rb' + - 'test/units/test_client_helper.rb' + - 'test/units/test_consumer.rb' + - 'test/units/test_net_http_client.rb' + - 'test/units/test_rsa_sha1.rb' + - 'test/units/test_server.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceBeforeBlockBraces: + Exclude: + - 'lib/oauth/request_proxy/action_controller_request.rb' + +# Offense count: 39 +# Cop supports --auto-correct. +Layout/SpaceBeforeComma: + Exclude: + - 'test/units/test_cli.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment. +Layout/SpaceBeforeFirstArg: + Exclude: + - 'test/units/test_consumer.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBrackets: space, no_space +Layout/SpaceInsideArrayLiteralBrackets: + Exclude: + - 'lib/oauth/request_proxy/net_http.rb' + - 'oauth.gemspec' + +# Offense count: 30 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideBlockBraces: + Exclude: + - 'lib/oauth/client/em_http.rb' + - 'lib/oauth/request_proxy/action_controller_request.rb' + - 'lib/oauth/request_proxy/base.rb' + - 'test/support/minitest_helpers.rb' + - 'test/units/test_consumer.rb' + +# Offense count: 450 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideHashLiteralBraces: + Enabled: false + +# Offense count: 58 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: space, compact, no_space +Layout/SpaceInsideParens: + Exclude: + - 'lib/oauth/client/helper.rb' + - 'lib/oauth/signature/rsa/sha1.rb' + - 'test/integration/consumer_test.rb' + - 'test/units/test_cli.rb' + - 'test/units/test_hmac_sha1.rb' + - 'test/units/test_hmac_sha256.rb' + - 'test/units/test_net_http_client.rb' + - 'test/units/test_rsa_sha1.rb' + - 'test/units/test_signature_plain_text.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Layout/SpaceInsidePercentLiteralDelimiters: + Exclude: + - 'lib/oauth/request_proxy/base.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: final_newline, final_blank_line +Layout/TrailingEmptyLines: + Exclude: + - '**/*.md' + - '**/*.markdown' + - 'lib/oauth/request_proxy/rest_client_request.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: AllowInHeredoc. +Layout/TrailingWhitespace: + Exclude: + - 'lib/oauth/request_proxy/rest_client_request.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +Lint/AmbiguousOperatorPrecedence: + Exclude: + - 'lib/oauth/cli/sign_command.rb' + - 'lib/oauth/consumer.rb' + - 'test/test_helper.rb' + +# Offense count: 2 +# Configuration parameters: AllowSafeAssignment. +Lint/AssignmentInCondition: + Exclude: + - 'lib/oauth/request_proxy/base.rb' + - 'lib/oauth/request_proxy/jabber_request.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Lint/DeprecatedOpenSSLConstant: + Exclude: + - 'lib/oauth/signature/hmac/sha1.rb' + - 'lib/oauth/signature/hmac/sha256.rb' + - 'lib/oauth/signature/rsa/sha1.rb' + +# Offense count: 1 +# Configuration parameters: AllowComments, AllowEmptyLambdas. +Lint/EmptyBlock: + Exclude: + - 'test/units/test_consumer.rb' + +# Offense count: 1 +# Configuration parameters: AllowComments. +Lint/EmptyWhen: + Exclude: + - 'lib/oauth/consumer.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: runtime_error, standard_error +Lint/InheritException: + Exclude: + - 'lib/oauth/request_proxy.rb' + - 'lib/oauth/signature.rb' + +# Offense count: 1 +Lint/MissingSuper: + Exclude: + - 'lib/oauth/errors/unauthorized.rb' + +# Offense count: 1 +Lint/OutOfRangeRegexpRef: + Exclude: + - 'test/cases/spec/1_0-final/test_parameter_encodings.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/RedundantStringCoercion: + Exclude: + - 'lib/oauth/consumer.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/SendWithMixinArgument: + Exclude: + - 'test/support/minitest_helpers.rb' + +# Offense count: 2 +# Configuration parameters: AllowKeywordBlockArguments. +Lint/UnderscorePrefixedVariableName: + Exclude: + - 'lib/oauth/consumer.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Exclude: + - '**/*.md' + - '**/*.markdown' + - 'lib/oauth/request_proxy/base.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. +Lint/UnusedMethodArgument: + Exclude: + - '**/*.md' + - '**/*.markdown' + - 'lib/oauth/consumer.rb' + - 'lib/oauth/server.rb' + +# Offense count: 1 +Lint/UselessAssignment: + Exclude: + - '**/*.md' + - '**/*.markdown' + - 'test/integration/consumer_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowComments. +Lint/UselessMethodDefinition: + Exclude: + - '**/*.md' + - '**/*.markdown' + - 'lib/oauth/signature/plaintext.rb' + +# Offense count: 50 +# Configuration parameters: IgnoredMethods, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 59 + +# Offense count: 9 +# Configuration parameters: CountComments, CountAsOne. +Metrics/ClassLength: + Max: 274 + +# Offense count: 7 +# Configuration parameters: IgnoredMethods. +Metrics/CyclomaticComplexity: + Max: 18 + +# Offense count: 64 +# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. +Metrics/MethodLength: + Max: 45 + +# Offense count: 1 +# Configuration parameters: Max, CountKeywordArgs. +Metrics/ParameterLists: + MaxOptionalParameters: 4 + +# Offense count: 7 +# Configuration parameters: IgnoredMethods. +Metrics/PerceivedComplexity: + Max: 17 + +# Offense count: 16 +# Cop supports --auto-correct. +Minitest/AssertEmptyLiteral: + Exclude: + - 'test/units/test_em_http_request_proxy.rb' + - 'test/units/test_oauth_helper.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Minitest/AssertIncludes: + Exclude: + - 'test/units/test_hmac_sha1.rb' + - 'test/units/test_hmac_sha256.rb' + - 'test/units/test_rsa_sha1.rb' + - 'test/units/test_signature_plain_text.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Minitest/AssertTruthy: + Exclude: + - 'test/units/test_consumer.rb' + +# Offense count: 1 +Minitest/AssertWithExpectedArgument: + Exclude: + - 'test/units/test_net_http_client.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +Minitest/LiteralAsActualArgument: + Exclude: + - 'test/support/minitest_helpers.rb' + - 'test/units/test_cli.rb' + - 'test/units/test_consumer.rb' + - 'test/units/test_net_http_client.rb' + +# Offense count: 31 +Minitest/MultipleAssertions: + Max: 18 + +# Offense count: 6 +# Cop supports --auto-correct. +Minitest/RefuteFalse: + Exclude: + - 'test/integration/consumer_test.rb' + - 'test/units/test_em_http_client.rb' + - 'test/units/test_signature_hmac_sha1.rb' + - 'test/units/test_signature_hmac_sha256.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Minitest/TestMethodName: + Exclude: + - 'test/units/test_action_controller_request_proxy.rb' + +# Offense count: 2 +Naming/AccessorMethodName: + Exclude: + - 'lib/oauth/cli/authorize_command.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Naming/BinaryOperatorParameterName: + Exclude: + - 'lib/oauth/signature/base.rb' + - 'lib/oauth/signature/plaintext.rb' + - 'lib/oauth/signature/rsa/sha1.rb' + +# Offense count: 2 +# Configuration parameters: ForbiddenDelimiters. +# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$)) +Naming/HeredocDelimiterNaming: + Exclude: + - 'lib/oauth/cli/help_command.rb' + - 'lib/oauth/cli/sign_command.rb' + +# Offense count: 1 +# Configuration parameters: EnforcedStyleForLeadingUnderscores. +# SupportedStylesForLeadingUnderscores: disallowed, required, optional +Naming/MemoizedInstanceVariableName: + Exclude: + - 'lib/oauth/client/em_http.rb' + +# Offense count: 5 +# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers. +# SupportedStyles: snake_case, normalcase, non_integer +# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339 +Naming/VariableNumber: + Exclude: + - 'test/cases/spec/1_0-final/test_parameter_encodings.rb' + - 'test/cases/spec/1_0-final/test_signature_base_strings.rb' + - 'test/integration/consumer_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Packaging/RequireRelativeHardcodingLib: + Exclude: + - 'bin/oauth' + +# Offense count: 2 +# Cop supports --auto-correct. +Performance/BlockGivenWithExplicitBlock: + Exclude: + - 'lib/oauth/consumer.rb' + - 'lib/oauth/signature/base.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Performance/Casecmp: + Exclude: + - 'lib/oauth/request_proxy/base.rb' + - 'lib/oauth/request_proxy/net_http.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: MaxKeyValuePairs. +Performance/RedundantMerge: + Exclude: + - 'lib/oauth/client/helper.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Performance/RegexpMatch: + Exclude: + - 'lib/oauth/cli/base_command.rb' + - 'lib/oauth/consumer.rb' + - 'test/cases/spec/1_0-final/test_parameter_encodings.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Performance/StringInclude: + Exclude: + - 'lib/oauth/cli/base_command.rb' + - 'lib/oauth/consumer.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Performance/StringReplacement: + Exclude: + - 'lib/oauth/signature/base.rb' + - 'lib/oauth/signature/hmac/sha1.rb' + - 'lib/oauth/signature/hmac/sha256.rb' + - 'lib/oauth/signature/rsa/sha1.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Security/IoMethods: + Exclude: + - 'lib/oauth/signature/rsa/sha1.rb' + - 'test/units/test_rsa_sha1.rb' + +# Offense count: 1 +Security/Open: + Exclude: + - 'lib/oauth/cli/base_command.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: prefer_alias, prefer_alias_method +Style/Alias: + Exclude: + - 'lib/oauth/helper.rb' + - 'lib/oauth/request_proxy/base.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, conditionals +Style/AndOr: + Exclude: + - 'lib/oauth/consumer.rb' + - 'lib/oauth/request_proxy/rack_request.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +Style/ArrayJoin: + Exclude: + - 'lib/oauth/cli/base_command.rb' + - 'lib/oauth/cli/sign_command.rb' + - 'lib/oauth/client/net_http.rb' + - 'lib/oauth/errors/unauthorized.rb' + - 'lib/oauth/helper.rb' + - 'lib/oauth/request_proxy/base.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. +# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces +# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object +# FunctionalMethods: let, let!, subject, watch +# IgnoredMethods: lambda, proc, it +Style/BlockDelimiters: + Exclude: + - 'test/units/test_signature_base.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/CaseLikeIf: + Exclude: + - 'lib/oauth/helper.rb' + - 'lib/oauth/signature/rsa/sha1.rb' + +# Offense count: 22 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: nested, compact +Style/ClassAndModuleChildren: + Enabled: false + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: is_a?, kind_of? +Style/ClassCheck: + Exclude: + - 'lib/oauth/client/em_http.rb' + - 'lib/oauth/client/helper.rb' + - 'lib/oauth/request_proxy.rb' + - 'lib/oauth/signature/base.rb' + +# Offense count: 2 +Style/ClassVars: + Exclude: + - 'lib/oauth/consumer.rb' + - 'lib/oauth/server.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/CollectionCompact: + Exclude: + - 'lib/oauth/cli/query_command.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: Keywords, RequireColon. +# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW, NOTE +Style/CommentAnnotation: + Exclude: + - '**/*.md' + - '**/*.markdown' + - 'lib/oauth/consumer.rb' + - 'lib/oauth/request_proxy/base.rb' + - 'lib/oauth/tokens/request_token.rb' + - 'test/units/test_action_controller_request_proxy.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. +# SupportedStyles: assign_to_condition, assign_inside_condition +Style/ConditionalAssignment: + Exclude: + - 'lib/oauth/client/em_http.rb' + - 'lib/oauth/client/net_http.rb' + - 'lib/oauth/consumer.rb' + - 'lib/oauth/request_proxy/base.rb' + - 'test/cases/spec/1_0-final/test_parameter_encodings.rb' + +# Offense count: 67 +# Configuration parameters: AllowedConstants. +Style/Documentation: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/EachWithObject: + Exclude: + - 'lib/oauth/consumer.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: compact, expanded +Style/EmptyMethod: + Exclude: + - 'lib/oauth/client/action_controller_request.rb' + - 'lib/oauth/request_proxy/rest_client_request.rb' + - 'test/units/test_request_token.rb' + - 'test/units/test_token.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/Encoding: + Exclude: + - 'oauth.gemspec' + - 'test/units/test_signature.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/EvenOdd: + Exclude: + - 'lib/oauth/helper.rb' + +# Offense count: 32 +# Cop supports --auto-correct. +Style/ExpandPathArguments: + Enabled: false + +# Offense count: 86 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +Style/GlobalStdStream: + Exclude: + - 'bin/oauth' + - 'examples/twitter.rb' + - 'examples/yql.rb' + - 'lib/oauth/request_proxy/base.rb' + +# Offense count: 3 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Exclude: + - 'lib/oauth/cli/sign_command.rb' + - 'lib/oauth/consumer.rb' + - 'lib/oauth/signature/base.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowSplatArgument. +Style/HashConversion: + Exclude: + - 'lib/oauth/tokens/request_token.rb' + +# Offense count: 491 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +Style/HashSyntax: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +Style/IfUnlessModifier: + Exclude: + - 'lib/oauth/cli/sign_command.rb' + - 'lib/oauth/client/em_http.rb' + - 'lib/oauth/consumer.rb' + - 'lib/oauth/request_proxy/action_controller_request.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: InverseMethods, InverseBlocks. +Style/InverseMethods: + Exclude: + - 'lib/oauth/request_proxy/base.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: line_count_dependent, lambda, literal +Style/Lambda: + Exclude: + - 'test/support/minitest_helpers.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +Style/MethodCallWithoutArgsParentheses: + Exclude: + - 'test/units/test_signature_base.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline +Style/MethodDefParentheses: + Exclude: + - 'test/units/test_consumer.rb' + - 'test/units/test_net_http_client.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, Autocorrect. +# SupportedStyles: module_function, extend_self, forbidden +Style/ModuleFunction: + Exclude: + - 'lib/oauth/helper.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/MultilineIfThen: + Exclude: + - 'lib/oauth/request_proxy/action_controller_request.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: literals, strict +Style/MutableConstant: + Exclude: + - 'lib/oauth/cli.rb' + - 'lib/oauth/consumer.rb' + - 'lib/oauth/oauth.rb' + - 'lib/oauth/version.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: both, prefix, postfix +Style/NegatedIf: + Exclude: + - 'lib/oauth/client/em_http.rb' + - 'lib/oauth/consumer.rb' + - 'lib/oauth/tokens/request_token.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: IncludeSemanticChanges. +Style/NonNilCheck: + Exclude: + - 'lib/oauth/request_proxy/net_http.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/Not: + Exclude: + - 'lib/oauth/request_proxy/base.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: Strict. +Style/NumericLiterals: + MinDigits: 40 + +# Offense count: 1 +# Configuration parameters: AllowedMethods. +# AllowedMethods: respond_to_missing? +Style/OptionalBooleanParameter: + Exclude: + - 'lib/oauth/request_proxy/base.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/ParallelAssignment: + Exclude: + - 'lib/oauth/cli/base_command.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowSafeAssignment, AllowInMultilineConditions. +Style/ParenthesesAroundCondition: + Exclude: + - 'lib/oauth/request_proxy/curb_request.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'lib/oauth/client/net_http.rb' + - 'lib/oauth/consumer.rb' + - 'lib/oauth/oauth.rb' + - 'lib/oauth/request_proxy/base.rb' + - 'lib/oauth/request_proxy/jabber_request.rb' + - 'test/units/test_signature.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/PerlBackrefs: + Exclude: + - 'test/cases/spec/1_0-final/test_parameter_encodings.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: short, verbose +Style/PreferredHashMethods: + Exclude: + - 'lib/oauth/consumer.rb' + - 'lib/oauth/request_proxy/em_http_request.rb' + - 'lib/oauth/request_proxy/net_http.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: . +# SupportedStyles: same_as_string_literals, single_quotes, double_quotes +Style/QuotedSymbols: + EnforcedStyle: single_quotes + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, AllowedCompactTypes. +# SupportedStyles: compact, exploded +Style/RaiseArgs: + Exclude: + - 'lib/oauth/helper.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Methods. +Style/RedundantArgument: + Exclude: + - 'lib/oauth/cli/base_command.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantAssignment: + Exclude: + - 'lib/oauth/request_proxy/rest_client_request.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantBegin: + Exclude: + - 'lib/oauth/consumer.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantCapitalW: + Exclude: + - 'lib/oauth/consumer.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +Style/RedundantRegexpEscape: + Exclude: + - 'lib/oauth/helper.rb' + - 'lib/oauth/oauth.rb' + - 'test/support/minitest_helpers.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleReturnValues. +Style/RedundantReturn: + Exclude: + - 'lib/oauth/request_proxy/base.rb' + - 'lib/oauth/request_proxy/curb_request.rb' + - 'test/units/test_consumer.rb' + +# Offense count: 19 +# Cop supports --auto-correct. +Style/RedundantSelf: + Exclude: + - 'lib/oauth/client/action_controller_request.rb' + - 'lib/oauth/client/em_http.rb' + - 'lib/oauth/client/net_http.rb' + - 'lib/oauth/consumer.rb' + - 'lib/oauth/signature.rb' + - 'lib/oauth/signature/base.rb' + - 'lib/oauth/tokens/consumer_token.rb' + - 'lib/oauth/tokens/request_token.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, AllowInnerSlashes. +# SupportedStyles: slashes, percent_r, mixed +Style/RegexpLiteral: + Exclude: + - 'lib/oauth/consumer.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: implicit, explicit +Style/RescueStandardError: + Exclude: + - 'lib/oauth/request_proxy/mock_request.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods. +# AllowedMethods: present?, blank?, presence, try, try! +Style/SafeNavigation: + Exclude: + - 'lib/oauth/request_proxy/net_http.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/SelectByRegexp: + Exclude: + - 'lib/oauth/consumer.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowAsExpressionSeparator. +Style/Semicolon: + Exclude: + - 'bin/oauth' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/SlicingWithRange: + Exclude: + - 'test/cases/spec/1_0-final/test_parameter_encodings.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: RequireEnglish, EnforcedStyle. +# SupportedStyles: use_perl_names, use_english_names +Style/SpecialGlobalVars: + Exclude: + - 'examples/twitter.rb' + - 'examples/yql.rb' + - 'oauth.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/StderrPuts: + Exclude: + - 'lib/oauth/request_proxy/base.rb' + +# Offense count: 17 +# Cop supports --auto-correct. +# Configuration parameters: Mode. +Style/StringConcatenation: + Exclude: + - 'lib/oauth/cli/sign_command.rb' + - 'lib/oauth/client/net_http.rb' + - 'test/integration/consumer_test.rb' + - 'test/test_helper.rb' + - 'test/units/test_net_http_client.rb' + - 'test/units/test_rsa_sha1.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiteralsInInterpolation: + Exclude: + - 'lib/oauth/request_proxy/base.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: . +# SupportedStyles: percent, brackets +Style/SymbolArray: + EnforcedStyle: percent + MinSize: 5 + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: AllowMethodsWithArguments, IgnoredMethods. +# IgnoredMethods: respond_to, define_method +Style/SymbolProc: + Exclude: + - 'lib/oauth/cli/query_command.rb' + - 'lib/oauth/client/em_http.rb' + - 'lib/oauth/request_proxy/base.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, AllowSafeAssignment. +# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex +Style/TernaryParentheses: + Exclude: + - 'lib/oauth/request_proxy/base.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: + Exclude: + - 'lib/oauth/cli.rb' + - 'test/units/test_client_helper.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, AllowedMethods. +# AllowedMethods: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym +Style/TrivialAccessors: + Exclude: + - 'lib/oauth/client/action_controller_request.rb' + - 'lib/oauth/client/helper.rb' + +# Offense count: 18 +# Cop supports --auto-correct. +# Configuration parameters: WordRegex. +# SupportedStyles: percent, brackets +Style/WordArray: + EnforcedStyle: percent + MinSize: 4 + +# Offense count: 119 +# Cop supports --auto-correct. +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +# IgnoredPatterns: (?-mix:^\#) +Layout/LineLength: + Max: 429 diff --git a/Gemfile b/Gemfile index fa75df15..b4e2a20b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ -source 'https://rubygems.org' +source "https://rubygems.org" gemspec diff --git a/Rakefile b/Rakefile index eee4d40a..9323eb28 100644 --- a/Rakefile +++ b/Rakefile @@ -1,13 +1,18 @@ -%w[rubygems rake rake/clean rake/testtask fileutils bundler].each { |f| require f } +# frozen_string_literal: true + +require "bundler/gem_tasks" +%w[rake/testtask fileutils].each { |f| require f } Bundler::GemHelper.install_tasks Rake::TestTask.new do |t| t.libs << "test" - t.test_files = FileList['test/**/*test*.rb'] + t.test_files = FileList["test/**/*test*.rb"] t.verbose = true end -Dir['tasks/**/*.rake'].each { |t| load t } +require "rubocop/rake_task" + +RuboCop::RakeTask.new -task :default => :test +task default: %i[test rubocop] diff --git a/bin/oauth b/bin/oauth index 0b01c831..d5f21857 100755 --- a/bin/oauth +++ b/bin/oauth @@ -1,11 +1,11 @@ #!/usr/bin/env ruby require_relative "../lib/oauth" -require 'oauth/cli' +require "oauth/cli" Signal.trap("INT") { puts; exit(1) } # don't dump a backtrace on a ^C -ARGV << 'help' if ARGV.empty? +ARGV << "help" if ARGV.empty? command = ARGV.shift OAuth::CLI.new(STDOUT, STDIN, STDERR, command, ARGV).run diff --git a/examples/twitter.rb b/examples/twitter.rb index e10eb422..80496a56 100644 --- a/examples/twitter.rb +++ b/examples/twitter.rb @@ -2,10 +2,10 @@ # # ./twitter.rb --consumer-key --consumer-secret -require 'oauth' -require 'optparse' -require 'json' -require 'pp' +require "oauth" +require "optparse" +require "json" +require "pp" options = {} diff --git a/examples/yql.rb b/examples/yql.rb index c9c6e343..7fed34ba 100755 --- a/examples/yql.rb +++ b/examples/yql.rb @@ -4,10 +4,10 @@ # ./yql.rb --consumer-key --consumer-secret "show tables" # ./yql.rb --consumer-key --consumer-secret "select * from flickr.photos.search where text='Cat' limit 10" -require 'oauth' -require 'optparse' -require 'json' -require 'pp' +require "oauth" +require "optparse" +require "json" +require "pp" options = {} diff --git a/lib/oauth.rb b/lib/oauth.rb index 7e08d046..968dd96b 100644 --- a/lib/oauth.rb +++ b/lib/oauth.rb @@ -1,12 +1,12 @@ root = File.dirname(__FILE__) $LOAD_PATH << root unless $LOAD_PATH.include?(root) -require 'oauth/version' +require "oauth/version" -require 'oauth/oauth' +require "oauth/oauth" -require 'oauth/client/helper' -require 'oauth/signature/hmac/sha1' -require 'oauth/signature/hmac/sha256' -require 'oauth/signature/rsa/sha1' -require 'oauth/request_proxy/mock_request' +require "oauth/client/helper" +require "oauth/signature/hmac/sha1" +require "oauth/signature/hmac/sha256" +require "oauth/signature/rsa/sha1" +require "oauth/request_proxy/mock_request" diff --git a/lib/oauth/cli.rb b/lib/oauth/cli.rb index 8c1dece8..ad0e185f 100644 --- a/lib/oauth/cli.rb +++ b/lib/oauth/cli.rb @@ -1,11 +1,11 @@ -require 'optparse' -require 'oauth/cli/base_command' -require 'oauth/cli/help_command' -require 'oauth/cli/query_command' -require 'oauth/cli/authorize_command' -require 'oauth/cli/sign_command' -require 'oauth/cli/version_command' -require 'active_support/core_ext/string/inflections' +require "optparse" +require "oauth/cli/base_command" +require "oauth/cli/help_command" +require "oauth/cli/query_command" +require "oauth/cli/authorize_command" +require "oauth/cli/sign_command" +require "oauth/cli/version_command" +require "active_support/core_ext/string/inflections" module OAuth class CLI @@ -14,11 +14,11 @@ def self.puts_red(string) end ALIASES = { - 'h' => 'help', - 'v' => 'version', - 'q' => 'query', - 'a' => 'authorize', - 's' => 'sign', + "h" => "help", + "v" => "version", + "q" => "query", + "a" => "authorize", + "s" => "sign", } def initialize(stdout, stdin, stderr, command, arguments) @@ -39,17 +39,17 @@ def get_command_class(command) def parse_command(command) case command = command.to_s.downcase - when '--version', '-v' - 'version' - when '--help', '-h', nil, '' - 'help' + when "--version", "-v" + "version" + when "--help", "-h", nil, "" + "help" when *ALIASES.keys ALIASES[command] when *ALIASES.values command else OAuth::CLI.puts_red "Command '#{command}' not found" - 'help' + "help" end end end diff --git a/lib/oauth/cli/base_command.rb b/lib/oauth/cli/base_command.rb index 9a3506b0..3f68a5ce 100644 --- a/lib/oauth/cli/base_command.rb +++ b/lib/oauth/cli/base_command.rb @@ -26,7 +26,7 @@ def required_options attr_reader :options def show_missing(array) - array = array.map { |s| "--#{s}" }.join(' ') + array = array.map { |s| "--#{s}" }.join(" ") OAuth::CLI.puts_red "Options missing to OAuth CLI: #{array}" end diff --git a/lib/oauth/client/action_controller_request.rb b/lib/oauth/client/action_controller_request.rb index e4618c11..f57c9c74 100644 --- a/lib/oauth/client/action_controller_request.rb +++ b/lib/oauth/client/action_controller_request.rb @@ -1,10 +1,10 @@ if defined? ActionDispatch - require 'oauth/request_proxy/rack_request' - require 'oauth/request_proxy/action_dispatch_request' - require 'action_dispatch/testing/test_process' + require "oauth/request_proxy/rack_request" + require "oauth/request_proxy/action_dispatch_request" + require "action_dispatch/testing/test_process" else - require 'oauth/request_proxy/action_controller_request' - require 'action_controller/test_process' + require "oauth/request_proxy/action_controller_request" + require "action_controller/test_process" end module ActionController @@ -35,7 +35,7 @@ def self.use_oauth? def configure_oauth(consumer = nil, token = nil, options = {}) @oauth_options = { :consumer => consumer, :token => token, - :scheme => 'header', + :scheme => "header", :signature_method => nil, :nonce => nil, :timestamp => nil }.merge(options) @@ -51,7 +51,7 @@ def apply_oauth! end def set_oauth_header - env['Authorization'] = @oauth_helper.header + env["Authorization"] = @oauth_helper.header end def set_oauth_parameters diff --git a/lib/oauth/client/em_http.rb b/lib/oauth/client/em_http.rb index 3b6a2676..0df6f0db 100644 --- a/lib/oauth/client/em_http.rb +++ b/lib/oauth/client/em_http.rb @@ -1,6 +1,6 @@ -require 'em-http' -require 'oauth/helper' -require 'oauth/request_proxy/em_http_request' +require "em-http" +require "oauth/helper" +require "oauth/request_proxy/em_http_request" # Extensions for em-http so that we can use consumer.sign! with an EventMachine::HttpClient # instance. This is purely syntactic sugar. @@ -26,7 +26,7 @@ def oauth!(http, consumer = nil, token = nil, options = {}) options = { :request_uri => normalized_oauth_uri(http), :consumer => consumer, :token => token, - :scheme => 'header', + :scheme => "header", :signature_method => nil, :nonce => nil, :timestamp => nil }.merge(options) @@ -52,7 +52,7 @@ def signature_base_string(http, consumer = nil, token = nil, options = {}) options = { :request_uri => normalized_oauth_uri(http), :consumer => consumer, :token => token, - :scheme => 'header', + :scheme => "header", :signature_method => nil, :nonce => nil, :timestamp => nil }.merge(options) @@ -78,7 +78,7 @@ def normalize_uri def combine_query(path, query, uri_query) combined_query = if query.kind_of?(Hash) - query.map { |k, v| encode_param(k, v) }.join('&') + query.map { |k, v| encode_param(k, v) }.join("&") else query.to_s end @@ -105,15 +105,15 @@ def normalized_oauth_uri(http) def set_oauth_header self.req[:head] ||= {} - self.req[:head].merge!('Authorization' => @oauth_helper.header) + self.req[:head].merge!("Authorization" => @oauth_helper.header) end def set_oauth_body - raise NotImplementedError, 'please use the set_oauth_header method instead' + raise NotImplementedError, "please use the set_oauth_header method instead" end def set_oauth_query_string - raise NotImplementedError, 'please use the set_oauth_header method instead' + raise NotImplementedError, "please use the set_oauth_header method instead" end end end diff --git a/lib/oauth/client/helper.rb b/lib/oauth/client/helper.rb index 5fe2be24..2d178190 100644 --- a/lib/oauth/client/helper.rb +++ b/lib/oauth/client/helper.rb @@ -1,8 +1,8 @@ -require 'oauth/client' -require 'oauth/consumer' -require 'oauth/helper' -require 'oauth/token' -require 'oauth/signature/hmac/sha1' +require "oauth/client" +require "oauth/consumer" +require "oauth/helper" +require "oauth/token" +require "oauth/signature/hmac/sha1" module OAuth::Client class Helper @@ -11,7 +11,7 @@ class Helper def initialize(request, options = {}) @request = request @options = options - @options[:signature_method] ||= 'HMAC-SHA1' + @options[:signature_method] ||= "HMAC-SHA1" end def options @@ -28,22 +28,22 @@ def timestamp def oauth_parameters out = { - 'oauth_body_hash' => options[:body_hash], - 'oauth_callback' => options[:oauth_callback], - 'oauth_consumer_key' => options[:consumer].key, - 'oauth_token' => options[:token] ? options[:token].token : '', - 'oauth_signature_method' => options[:signature_method], - 'oauth_timestamp' => timestamp, - 'oauth_nonce' => nonce, - 'oauth_verifier' => options[:oauth_verifier], - 'oauth_version' => (options[:oauth_version] || '1.0'), - 'oauth_session_handle' => options[:oauth_session_handle] + "oauth_body_hash" => options[:body_hash], + "oauth_callback" => options[:oauth_callback], + "oauth_consumer_key" => options[:consumer].key, + "oauth_token" => options[:token] ? options[:token].token : "", + "oauth_signature_method" => options[:signature_method], + "oauth_timestamp" => timestamp, + "oauth_nonce" => nonce, + "oauth_verifier" => options[:oauth_verifier], + "oauth_version" => (options[:oauth_version] || "1.0"), + "oauth_session_handle" => options[:oauth_session_handle] } allowed_empty_params = options[:allow_empty_params] if allowed_empty_params != true && !allowed_empty_params.kind_of?(Array) allowed_empty_params = allowed_empty_params == false ? [] : [allowed_empty_params] end - out.select! { |k,v| v.to_s != '' || allowed_empty_params == true || allowed_empty_params.include?(k) } + out.select! { |k,v| v.to_s != "" || allowed_empty_params == true || allowed_empty_params.include?(k) } out end @@ -73,18 +73,18 @@ def hash_body def amend_user_agent_header(headers) @oauth_ua_string ||= "OAuth gem v#{OAuth::VERSION}" # Net::HTTP in 1.9 appends Ruby - if headers['User-Agent'] && headers['User-Agent'] != 'Ruby' - headers['User-Agent'] += " (#{@oauth_ua_string})" + if headers["User-Agent"] && headers["User-Agent"] != "Ruby" + headers["User-Agent"] += " (#{@oauth_ua_string})" else - headers['User-Agent'] = @oauth_ua_string + headers["User-Agent"] = @oauth_ua_string end end def header parameters = oauth_parameters - parameters.merge!('oauth_signature' => signature(options.merge(:parameters => parameters))) + parameters.merge!("oauth_signature" => signature(options.merge(:parameters => parameters))) - header_params_str = parameters.sort.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(', ') + header_params_str = parameters.sort.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(", ") realm = "realm=\"#{options[:realm]}\", " if options[:realm] "OAuth #{realm}#{header_params_str}" diff --git a/lib/oauth/client/net_http.rb b/lib/oauth/client/net_http.rb index 0e752de6..60b9ed8d 100644 --- a/lib/oauth/client/net_http.rb +++ b/lib/oauth/client/net_http.rb @@ -1,5 +1,5 @@ -require 'oauth/helper' -require 'oauth/request_proxy/net_http' +require "oauth/helper" +require "oauth/request_proxy/net_http" class Net::HTTPGenericRequest include OAuth::Helper @@ -58,7 +58,7 @@ def oauth_helper_options(http, consumer, token, options) { :request_uri => oauth_full_request_uri(http,options), :consumer => consumer, :token => token, - :scheme => 'header', + :scheme => "header", :signature_method => nil, :nonce => nil, :timestamp => nil }.merge(options) @@ -71,7 +71,7 @@ def oauth_full_request_uri(http,options) if options[:request_endpoint] && options[:site] is_https = options[:site].match(%r(^https://)) - uri.host = options[:site].gsub(%r(^https?://), '') + uri.host = options[:site].gsub(%r(^https?://), "") uri.port ||= is_https ? 443 : 80 end @@ -89,7 +89,7 @@ def oauth_body_hash_required? end def set_oauth_header - self['Authorization'] = @oauth_helper.header + self["Authorization"] = @oauth_helper.header end # FIXME: if you're using a POST body and query string parameters, this method diff --git a/lib/oauth/consumer.rb b/lib/oauth/consumer.rb index fd2f3185..1cea4203 100644 --- a/lib/oauth/consumer.rb +++ b/lib/oauth/consumer.rb @@ -1,16 +1,16 @@ -require 'net/http' -require 'net/https' -require 'oauth/oauth' -require 'oauth/client/net_http' -require 'oauth/errors' -require 'cgi' +require "net/http" +require "net/https" +require "oauth/oauth" +require "oauth/client/net_http" +require "oauth/errors" +require "cgi" module OAuth class Consumer # determine the certificate authority path to verify SSL certs - if ENV['SSL_CERT_FILE'] - if File.exist?(ENV['SSL_CERT_FILE']) - CA_FILE = ENV['SSL_CERT_FILE'] + if ENV["SSL_CERT_FILE"] + if File.exist?(ENV["SSL_CERT_FILE"]) + CA_FILE = ENV["SSL_CERT_FILE"] else raise "The SSL CERT provided does not exist." end @@ -29,13 +29,13 @@ class Consumer @@default_options = { # Signature method used by server. Defaults to HMAC-SHA1 - :signature_method => 'HMAC-SHA1', + :signature_method => "HMAC-SHA1", # default paths on site. These are the same as the defaults set up by the generators - :request_token_path => '/oauth/request_token', - :authenticate_path => '/oauth/authenticate', - :authorize_path => '/oauth/authorize', - :access_token_path => '/oauth/access_token', + :request_token_path => "/oauth/request_token", + :authenticate_path => "/oauth/authenticate", + :authorize_path => "/oauth/authorize", + :access_token_path => "/oauth/access_token", :proxy => nil, # How do we send the oauth values to the server see @@ -240,7 +240,7 @@ def token_request(http_method, path, token = nil, request_options = {}, *argumen end when (300..399) # this is a redirect - uri = URI.parse(response['location']) + uri = URI.parse(response["location"]) our_uri = URI.parse(site) if uri.path == path && our_uri.host != uri.host @@ -358,7 +358,7 @@ def create_http(_url = nil) http_object = Net::HTTP.new(our_uri.host, our_uri.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password) end - http_object.use_ssl = (our_uri.scheme == 'https') + http_object.use_ssl = (our_uri.scheme == "https") if @options[:no_verify] http_object.verify_mode = OpenSSL::SSL::VERIFY_NONE @@ -391,20 +391,20 @@ def create_http_request(http_method, path, *arguments) # only add if the site host matches the current http object's host # (in case we've specified a full url for token requests) uri = URI.parse(site) - path = uri.path + path if uri.path && uri.path != '/' && uri.host == http.address + path = uri.path + path if uri.path && uri.path != "/" && uri.host == http.address headers = arguments.first.is_a?(Hash) ? arguments.shift : {} case http_method when :post request = Net::HTTP::Post.new(path,headers) - request["Content-Length"] = '0' # Default to 0 + request["Content-Length"] = "0" # Default to 0 when :put request = Net::HTTP::Put.new(path,headers) - request["Content-Length"] = '0' # Default to 0 + request["Content-Length"] = "0" # Default to 0 when :patch request = Net::HTTP::Patch.new(path,headers) - request["Content-Length"] = '0' # Default to 0 + request["Content-Length"] = "0" # Default to 0 when :get request = Net::HTTP::Get.new(path,headers) when :delete @@ -417,7 +417,7 @@ def create_http_request(http_method, path, *arguments) if data.is_a?(Hash) request.body = OAuth::Helper.normalize(data) - request.content_type = 'application/x-www-form-urlencoded' + request.content_type = "application/x-www-form-urlencoded" elsif data if data.respond_to?(:read) request.body_stream = data diff --git a/lib/oauth/errors.rb b/lib/oauth/errors.rb index 94b9b23d..3ba6f2b6 100644 --- a/lib/oauth/errors.rb +++ b/lib/oauth/errors.rb @@ -1,3 +1,3 @@ -require 'oauth/errors/error' -require 'oauth/errors/unauthorized' -require 'oauth/errors/problem' +require "oauth/errors/error" +require "oauth/errors/unauthorized" +require "oauth/errors/problem" diff --git a/lib/oauth/helper.rb b/lib/oauth/helper.rb index f8fbf7d9..defb8c7f 100644 --- a/lib/oauth/helper.rb +++ b/lib/oauth/helper.rb @@ -1,5 +1,5 @@ -require 'openssl' -require 'base64' +require "openssl" +require "base64" module OAuth module Helper @@ -19,13 +19,13 @@ def _escape(string) end def unescape(value) - URI::DEFAULT_PARSER.unescape(value.gsub('+', '%2B')) + URI::DEFAULT_PARSER.unescape(value.gsub("+", "%2B")) end # Generate a random key of up to +size+ bytes. The value returned is Base64 encoded with non-word # characters removed. def generate_key(size=32) - Base64.encode64(OpenSSL::Random.random_bytes(size)).gsub(/\W/, '') + Base64.encode64(OpenSSL::Random.random_bytes(size)).gsub(/\W/, "") end alias_method :generate_nonce, :generate_key diff --git a/lib/oauth/oauth_test_helper.rb b/lib/oauth/oauth_test_helper.rb index a59b4cb6..7aa03103 100644 --- a/lib/oauth/oauth_test_helper.rb +++ b/lib/oauth/oauth_test_helper.rb @@ -1,5 +1,5 @@ -require 'action_controller' -require 'action_controller/test_process' +require "action_controller" +require "action_controller/test_process" module OAuth module OAuthTestHelper @@ -8,7 +8,7 @@ def mock_incoming_request_with_query(request) incoming.request_uri = request.path incoming.host = request.uri.host incoming.env["SERVER_PORT"] = request.uri.port - incoming.env['REQUEST_METHOD'] = request.http_method + incoming.env["REQUEST_METHOD"] = request.http_method incoming end @@ -18,7 +18,7 @@ def mock_incoming_request_with_authorize_header(request) incoming.host = request.uri.host incoming.env["HTTP_AUTHORIZATION"] = request.to_auth_string incoming.env["SERVER_PORT"] = request.uri.port - incoming.env['REQUEST_METHOD'] = request.http_method + incoming.env["REQUEST_METHOD"] = request.http_method incoming end end diff --git a/lib/oauth/request_proxy/action_controller_request.rb b/lib/oauth/request_proxy/action_controller_request.rb index 065279ee..208174ce 100644 --- a/lib/oauth/request_proxy/action_controller_request.rb +++ b/lib/oauth/request_proxy/action_controller_request.rb @@ -1,12 +1,12 @@ -require 'active_support' +require "active_support" require "active_support/version" -require 'action_controller' -require 'uri' +require "action_controller" +require "uri" if Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3") then # rails 2.x - require 'action_controller/request' + require "action_controller/request" unless ActionController::Request::HTTP_METHODS.include?("patch") ActionController::Request::HTTP_METHODS << "patch" ActionController::Request::HTTP_METHOD_LOOKUP["PATCH"] = :patch @@ -16,7 +16,7 @@ elsif Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4") then # rails 3.x - require 'action_dispatch/http/request' + require "action_dispatch/http/request" unless ActionDispatch::Request::HTTP_METHODS.include?("patch") ActionDispatch::Request::HTTP_METHODS << "patch" ActionDispatch::Request::HTTP_METHOD_LOOKUP["PATCH"] = :patch @@ -24,7 +24,7 @@ end else # rails 4.x and later - already has patch - require 'action_dispatch/http/request' + require "action_dispatch/http/request" end module OAuth::RequestProxy @@ -66,10 +66,10 @@ def parameters_for_signature end params. - join('&').split('&'). + join("&").split("&"). reject { |s| s.match(/\A\s*\z/) }. - map { |p| p.split('=').map{|esc| CGI.unescape(esc)} }. - reject { |kv| kv[0] == 'oauth_signature'} + map { |p| p.split("=").map{|esc| CGI.unescape(esc)} }. + reject { |kv| kv[0] == "oauth_signature"} end def raw_post_signature? diff --git a/lib/oauth/request_proxy/action_dispatch_request.rb b/lib/oauth/request_proxy/action_dispatch_request.rb index be6f8d7d..635f5a0d 100644 --- a/lib/oauth/request_proxy/action_dispatch_request.rb +++ b/lib/oauth/request_proxy/action_dispatch_request.rb @@ -1,4 +1,4 @@ -require 'oauth/request_proxy/rack_request' +require "oauth/request_proxy/rack_request" module OAuth::RequestProxy class ActionDispatchRequest < OAuth::RequestProxy::RackRequest diff --git a/lib/oauth/request_proxy/base.rb b/lib/oauth/request_proxy/base.rb index c1a8c57a..31af01b7 100644 --- a/lib/oauth/request_proxy/base.rb +++ b/lib/oauth/request_proxy/base.rb @@ -1,5 +1,5 @@ -require 'oauth/request_proxy' -require 'oauth/helper' +require "oauth/request_proxy" +require "oauth/helper" module OAuth::RequestProxy class Base @@ -20,41 +20,41 @@ def initialize(request, options = {}) ## OAuth parameters def oauth_callback - parameters['oauth_callback'] + parameters["oauth_callback"] end def oauth_consumer_key - parameters['oauth_consumer_key'] + parameters["oauth_consumer_key"] end def oauth_nonce - parameters['oauth_nonce'] + parameters["oauth_nonce"] end def oauth_signature # TODO can this be nil? - [parameters['oauth_signature']].flatten.first || "" + [parameters["oauth_signature"]].flatten.first || "" end def oauth_signature_method - case parameters['oauth_signature_method'] + case parameters["oauth_signature_method"] when Array - parameters['oauth_signature_method'].first + parameters["oauth_signature_method"].first else - parameters['oauth_signature_method'] + parameters["oauth_signature_method"] end end def oauth_timestamp - parameters['oauth_timestamp'] + parameters["oauth_timestamp"] end def oauth_token - parameters['oauth_token'] + parameters["oauth_token"] end def oauth_verifier - parameters['oauth_verifier'] + parameters["oauth_verifier"] end def oauth_version @@ -140,15 +140,15 @@ def signed_uri(with_oauth = true) # Authorization header for OAuth def oauth_header(options = {}) - header_params_str = oauth_parameters.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(', ') + header_params_str = oauth_parameters.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(", ") realm = "realm=\"#{options[:realm]}\", " if options[:realm] "OAuth #{realm}#{header_params_str}" end def query_string_blank? - if uri = request.env['REQUEST_URI'] - uri.split('?', 2)[1].nil? + if uri = request.env["REQUEST_URI"] + uri.split("?", 2)[1].nil? else request.query_string.match(/\A\s*\z/) end @@ -161,7 +161,7 @@ def header_params next unless request.env.include?(header) header = request.env[header] - next unless header[0,6] == 'OAuth ' + next unless header[0,6] == "OAuth " # parse the header into a Hash oauth_params = OAuth::Helper.parse_header(header) diff --git a/lib/oauth/request_proxy/curb_request.rb b/lib/oauth/request_proxy/curb_request.rb index 1cace66f..d61cfcb2 100644 --- a/lib/oauth/request_proxy/curb_request.rb +++ b/lib/oauth/request_proxy/curb_request.rb @@ -1,7 +1,7 @@ - require 'oauth/request_proxy/base' -require 'curb' -require 'uri' -require 'cgi' + require "oauth/request_proxy/base" +require "curb" +require "uri" +require "cgi" module OAuth::RequestProxy::Curl class Easy < OAuth::RequestProxy::Base @@ -42,7 +42,7 @@ def post_parameters post_body = {} # Post params are only used if posting form data - if (request.headers['Content-Type'] && request.headers['Content-Type'].to_s.downcase.start_with?("application/x-www-form-urlencoded")) + if (request.headers["Content-Type"] && request.headers["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded")) request.post_body.split("&").each do |str| param = str.split("=") diff --git a/lib/oauth/request_proxy/em_http_request.rb b/lib/oauth/request_proxy/em_http_request.rb index eb193935..741560bc 100644 --- a/lib/oauth/request_proxy/em_http_request.rb +++ b/lib/oauth/request_proxy/em_http_request.rb @@ -1,7 +1,7 @@ -require 'oauth/request_proxy/base' +require "oauth/request_proxy/base" # em-http also uses adddressable so there is no need to require uri. -require 'em-http' -require 'cgi' +require "em-http" +require "cgi" module OAuth::RequestProxy::EventMachine class HttpRequest < OAuth::RequestProxy::Base @@ -47,8 +47,8 @@ def query_parameters def post_parameters headers = request.req[:head] || {} - form_encoded = headers['Content-Type'].to_s.downcase.start_with?("application/x-www-form-urlencoded") - if ['POST', 'PUT'].include?(method) && form_encoded + form_encoded = headers["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded") + if ["POST", "PUT"].include?(method) && form_encoded CGI.parse(request.normalize_body(request.req[:body]).to_s) else {} diff --git a/lib/oauth/request_proxy/jabber_request.rb b/lib/oauth/request_proxy/jabber_request.rb index 5c44b5b5..2ff1bb4a 100644 --- a/lib/oauth/request_proxy/jabber_request.rb +++ b/lib/oauth/request_proxy/jabber_request.rb @@ -1,5 +1,5 @@ -require 'xmpp4r' -require 'oauth/request_proxy/base' +require "xmpp4r" +require "oauth/request_proxy/base" module OAuth module RequestProxy @@ -13,7 +13,7 @@ def parameters @params = {} - oauth = @request.get_elements('//oauth').first + oauth = @request.get_elements("//oauth").first return @params unless oauth %w( oauth_token oauth_consumer_key oauth_signature_method oauth_signature diff --git a/lib/oauth/request_proxy/mock_request.rb b/lib/oauth/request_proxy/mock_request.rb index e7c2d660..db0ba83d 100644 --- a/lib/oauth/request_proxy/mock_request.rb +++ b/lib/oauth/request_proxy/mock_request.rb @@ -1,4 +1,4 @@ -require 'oauth/request_proxy/base' +require "oauth/request_proxy/base" module OAuth module RequestProxy diff --git a/lib/oauth/request_proxy/net_http.rb b/lib/oauth/request_proxy/net_http.rb index 59d0dbc1..0d0d6fb2 100644 --- a/lib/oauth/request_proxy/net_http.rb +++ b/lib/oauth/request_proxy/net_http.rb @@ -1,7 +1,7 @@ -require 'oauth/request_proxy/base' -require 'net/http' -require 'uri' -require 'cgi' +require "oauth/request_proxy/base" +require "net/http" +require "uri" +require "cgi" module OAuth::RequestProxy::Net module HTTP @@ -48,12 +48,12 @@ def all_parameters def query_string params = [ query_params, auth_header_params ] - params << post_params if (method.to_s.upcase == 'POST' || method.to_s.upcase == 'PUT') && form_url_encoded? - params.compact.join('&') + params << post_params if (method.to_s.upcase == "POST" || method.to_s.upcase == "PUT") && form_url_encoded? + params.compact.join("&") end def form_url_encoded? - request['Content-Type'] != nil && request['Content-Type'].to_s.downcase.start_with?('application/x-www-form-urlencoded') + request["Content-Type"] != nil && request["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded") end def query_params @@ -65,8 +65,8 @@ def post_params end def auth_header_params - return nil unless request['Authorization'] && request['Authorization'][0,5] == 'OAuth' - request['Authorization'] + return nil unless request["Authorization"] && request["Authorization"][0,5] == "OAuth" + request["Authorization"] end end end diff --git a/lib/oauth/request_proxy/rack_request.rb b/lib/oauth/request_proxy/rack_request.rb index 9ad4c5cd..5039ab48 100644 --- a/lib/oauth/request_proxy/rack_request.rb +++ b/lib/oauth/request_proxy/rack_request.rb @@ -1,6 +1,6 @@ -require 'oauth/request_proxy/base' -require 'uri' -require 'rack' +require "oauth/request_proxy/base" +require "uri" +require "rack" module OAuth::RequestProxy class RackRequest < OAuth::RequestProxy::Base @@ -24,7 +24,7 @@ def parameters end def signature - parameters['oauth_signature'] + parameters["oauth_signature"] end protected diff --git a/lib/oauth/request_proxy/rest_client_request.rb b/lib/oauth/request_proxy/rest_client_request.rb index b49e24a9..e7175b32 100644 --- a/lib/oauth/request_proxy/rest_client_request.rb +++ b/lib/oauth/request_proxy/rest_client_request.rb @@ -1,7 +1,7 @@ -require 'oauth/request_proxy/base' -require 'rest-client' -require 'uri' -require 'cgi' +require "oauth/request_proxy/base" +require "rest-client" +require "uri" +require "cgi" module OAuth::RequestProxy::RestClient class Request < OAuth::RequestProxy::Base @@ -35,7 +35,7 @@ def request_params def post_parameters # Post params are only used if posting form data - if method == 'POST' || method == 'PUT' + if method == "POST" || method == "PUT" OAuth::Helper.stringify_keys(query_string_to_hash(request.payload.to_s) || {}) else {} @@ -45,8 +45,8 @@ def post_parameters private def query_string_to_hash(query) - keyvals = query.split('&').inject({}) do |result, q| - k,v = q.split('=') + keyvals = query.split("&").inject({}) do |result, q| + k,v = q.split("=") if !v.nil? result.merge({k => v}) elsif !result.key?(k) diff --git a/lib/oauth/request_proxy/typhoeus_request.rb b/lib/oauth/request_proxy/typhoeus_request.rb index ebcb3545..8ba17aaa 100644 --- a/lib/oauth/request_proxy/typhoeus_request.rb +++ b/lib/oauth/request_proxy/typhoeus_request.rb @@ -1,8 +1,8 @@ -require 'oauth/request_proxy/base' -require 'typhoeus' -require 'typhoeus/request' -require 'uri' -require 'cgi' +require "oauth/request_proxy/base" +require "typhoeus" +require "typhoeus/request" +require "uri" +require "cgi" module OAuth::RequestProxy::Typhoeus class Request < OAuth::RequestProxy::Base @@ -20,7 +20,7 @@ class Request < OAuth::RequestProxy::Base def method request_method = request.options[:method].to_s.upcase - request_method.empty? ? 'GET' : request_method + request_method.empty? ? "GET" : request_method end def uri @@ -44,7 +44,7 @@ def query_parameters def post_parameters # Post params are only used if posting form data - if method == 'POST' + if method == "POST" OAuth::Helper.stringify_keys(request.options[:params] || {}) else {} diff --git a/lib/oauth/server.rb b/lib/oauth/server.rb index 1aa4f316..7038961a 100644 --- a/lib/oauth/server.rb +++ b/lib/oauth/server.rb @@ -1,5 +1,5 @@ -require 'oauth/helper' -require 'oauth/consumer' +require "oauth/helper" +require "oauth/consumer" module OAuth # This is mainly used to create consumer credentials and can pretty much be ignored if you want to create your own diff --git a/lib/oauth/signature/base.rb b/lib/oauth/signature/base.rb index b8ab8feb..9110e464 100644 --- a/lib/oauth/signature/base.rb +++ b/lib/oauth/signature/base.rb @@ -1,7 +1,7 @@ -require 'oauth/signature' -require 'oauth/helper' -require 'oauth/request_proxy/base' -require 'base64' +require "oauth/signature" +require "oauth/helper" +require "oauth/request_proxy/base" +require "base64" module OAuth::Signature class Base @@ -47,7 +47,7 @@ def initialize(request, options = {}, &block) end def signature - Base64.encode64(digest).chomp.gsub(/\n/,'') + Base64.encode64(digest).chomp.gsub(/\n/,"") end def ==(cmp_signature) diff --git a/lib/oauth/signature/hmac/sha1.rb b/lib/oauth/signature/hmac/sha1.rb index ccddf419..ccde6584 100644 --- a/lib/oauth/signature/hmac/sha1.rb +++ b/lib/oauth/signature/hmac/sha1.rb @@ -1,17 +1,17 @@ -require 'oauth/signature/base' +require "oauth/signature/base" module OAuth::Signature::HMAC class SHA1 < OAuth::Signature::Base - implements 'hmac-sha1' + implements "hmac-sha1" def body_hash - Base64.encode64(OpenSSL::Digest::SHA1.digest(request.body || '')).chomp.gsub(/\n/,'') + Base64.encode64(OpenSSL::Digest::SHA1.digest(request.body || "")).chomp.gsub(/\n/,"") end private def digest - OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), secret, signature_base_string) + OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha1"), secret, signature_base_string) end end end diff --git a/lib/oauth/signature/hmac/sha256.rb b/lib/oauth/signature/hmac/sha256.rb index 0c3d38fb..9a7b5305 100644 --- a/lib/oauth/signature/hmac/sha256.rb +++ b/lib/oauth/signature/hmac/sha256.rb @@ -1,17 +1,17 @@ -require 'oauth/signature/base' +require "oauth/signature/base" module OAuth::Signature::HMAC class SHA256 < OAuth::Signature::Base - implements 'hmac-sha256' + implements "hmac-sha256" def body_hash - Base64.encode64(OpenSSL::Digest::SHA256.digest(request.body || '')).chomp.gsub(/\n/,'') + Base64.encode64(OpenSSL::Digest::SHA256.digest(request.body || "")).chomp.gsub(/\n/,"") end private def digest - OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), secret, signature_base_string) + OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha256"), secret, signature_base_string) end end end diff --git a/lib/oauth/signature/plaintext.rb b/lib/oauth/signature/plaintext.rb index 43c10284..3a727c2c 100644 --- a/lib/oauth/signature/plaintext.rb +++ b/lib/oauth/signature/plaintext.rb @@ -1,8 +1,8 @@ -require 'oauth/signature/base' +require "oauth/signature/base" module OAuth::Signature class PLAINTEXT < Base - implements 'plaintext' + implements "plaintext" def signature signature_base_string diff --git a/lib/oauth/signature/rsa/sha1.rb b/lib/oauth/signature/rsa/sha1.rb index 276e2e47..9978aed3 100644 --- a/lib/oauth/signature/rsa/sha1.rb +++ b/lib/oauth/signature/rsa/sha1.rb @@ -1,8 +1,8 @@ -require 'oauth/signature/base' +require "oauth/signature/base" module OAuth::Signature::RSA class SHA1 < OAuth::Signature::Base - implements 'rsa-sha1' + implements "rsa-sha1" def ==(cmp_signature) public_key.verify(OpenSSL::Digest::SHA1.new, Base64.decode64(cmp_signature.is_a?(Array) ? cmp_signature.first : cmp_signature), signature_base_string) @@ -19,7 +19,7 @@ def public_key end def body_hash - Base64.encode64(OpenSSL::Digest::SHA1.digest(request.body || '')).chomp.gsub(/\n/,'') + Base64.encode64(OpenSSL::Digest::SHA1.digest(request.body || "")).chomp.gsub(/\n/,"") end private diff --git a/lib/oauth/token.rb b/lib/oauth/token.rb index 056aba93..fab87bdc 100644 --- a/lib/oauth/token.rb +++ b/lib/oauth/token.rb @@ -1,7 +1,7 @@ # this exists for backwards-compatibility -require 'oauth/tokens/token' -require 'oauth/tokens/server_token' -require 'oauth/tokens/consumer_token' -require 'oauth/tokens/request_token' -require 'oauth/tokens/access_token' +require "oauth/tokens/token" +require "oauth/tokens/server_token" +require "oauth/tokens/consumer_token" +require "oauth/tokens/request_token" +require "oauth/tokens/access_token" diff --git a/lib/oauth/tokens/access_token.rb b/lib/oauth/tokens/access_token.rb index 35a2ef76..b3351a97 100644 --- a/lib/oauth/tokens/access_token.rb +++ b/lib/oauth/tokens/access_token.rb @@ -43,7 +43,7 @@ def head(path, headers = {}) # @response = @token.post('/people', nil, {'Accept' => 'application/xml' }) # @response = @token.post('/people', @person.to_xml, { 'Accept'=>'application/xml', 'Content-Type' => 'application/xml' }) # - def post(path, body = '', headers = {}) + def post(path, body = "", headers = {}) request(:post, path, body, headers) end @@ -55,7 +55,7 @@ def post(path, body = '', headers = {}) # @response = @token.put('/people/123', nil, { 'Accept' => 'application/xml' }) # @response = @token.put('/people/123', @person.to_xml, { 'Accept' => 'application/xml', 'Content-Type' => 'application/xml' }) # - def put(path, body = '', headers = {}) + def put(path, body = "", headers = {}) request(:put, path, body, headers) end @@ -67,7 +67,7 @@ def put(path, body = '', headers = {}) # @response = @token.patch('/people/123', nil, { 'Accept' => 'application/xml' }) # @response = @token.patch('/people/123', @person.to_xml, { 'Accept' => 'application/xml', 'Content-Type' => 'application/xml' }) # - def patch(path, body = '', headers = {}) + def patch(path, body = "", headers = {}) request(:patch, path, body, headers) end diff --git a/oauth.gemspec b/oauth.gemspec index 7cd88a3e..adcd4793 100644 --- a/oauth.gemspec +++ b/oauth.gemspec @@ -11,41 +11,49 @@ Gem::Specification.new do |spec| spec.license = "MIT" spec.authors = ["Pelle Braendgaard", "Blaine Cook", "Larry Halff", "Jesse Clark", "Jon Crosby", "Seth Fitzsimmons", "Matt Sanford", "Aaron Quint"] - spec.email = "oauth-ruby@googlegroupspec.com" + spec.email = "oauth-ruby@googlegroups.com" spec.summary = "OAuth Core Ruby implementation" spec.executables = ["oauth"] spec.homepage = "https://github.com/oauth-xx/oauth-ruby" spec.metadata = { - 'bug_tracker_uri' => "#{spec.homepage}/issues", - 'changelog_uri' => "#{spec.homepage}/blob/master/HISTORY", - 'documentation_uri' => "https://rdoc.info/github/oauth-xx/oauth-ruby/master/frames", - 'homepage_uri' => spec.homepage, - 'source_code_uri' => spec.homepage + "bug_tracker_uri" => "#{spec.homepage}/issues", + "changelog_uri" => "#{spec.homepage}/blob/master/HISTORY", + "documentation_uri" => "https://rubydoc.info/github/oauth-xx/oauth-ruby/master", + "homepage_uri" => spec.homepage, + "source_code_uri" => spec.homepage } - spec.files = Dir.glob("lib/**/*.rb") + spec.files = Dir.glob("lib/**/*.rb") + ["LICENSE", "README.rdoc", "HISTORY"] #spec.test_files = Dir.glob("test/**/*.rb") + Dir.glob('test/keys/*') spec.extra_rdoc_files = [ "LICENSE", "README.rdoc", "TODO" ] # This gem will work with 2.0 or greater... - spec.required_ruby_version = '>= 2.0' + spec.required_ruby_version = ">= 2.0" # Nokogiri 1.7 does not accept Ruby 2.0 spec.add_development_dependency("nokogiri", "~> 1.6.8") if RUBY_VERSION < "2.1" - spec.add_development_dependency("rake") - spec.add_development_dependency("minitest") - spec.add_development_dependency("byebug") spec.add_development_dependency("actionpack", ">= 5.0") + spec.add_development_dependency("byebug", "~> 11.1") + spec.add_development_dependency("curb") + spec.add_development_dependency("em-http-request", "~> 1.1.7") spec.add_development_dependency("iconv") + spec.add_development_dependency("minitest") + spec.add_development_dependency("mocha", ">= 0.9.12", "<=1.1.0") spec.add_development_dependency("rack", "~> 2.0") spec.add_development_dependency("rack-test") - spec.add_development_dependency("mocha", ">= 0.9.12", "<=1.1.0") - spec.add_development_dependency("typhoeus", ">= 0.1.13") - spec.add_development_dependency("em-http-request", "~> 1.1.7") - spec.add_development_dependency("curb") - spec.add_development_dependency("webmock", "< 2.0") + spec.add_development_dependency("rake", "~> 13.0") spec.add_development_dependency("rest-client") - spec.add_development_dependency("simplecov") + spec.add_development_dependency("rubocop", "~> 1.22") + spec.add_development_dependency("rubocop-faker", "~> 1.1") + spec.add_development_dependency("rubocop-md", "~> 1.0") + spec.add_development_dependency("rubocop-minitest", "~> 0.15") + spec.add_development_dependency("rubocop-packaging", "~> 0.5") + spec.add_development_dependency("rubocop-performance", "~> 1.11") + spec.add_development_dependency("rubocop-rake", "~> 0.6") + spec.add_development_dependency("rubocop-thread_safety", "~> 0.4") + spec.add_development_dependency("simplecov", "~> 0.21") spec.add_development_dependency("simplecov-cobertura", "~> 1.4") + spec.add_development_dependency("typhoeus", ">= 0.1.13") + spec.add_development_dependency("webmock", "< 2.0") end diff --git a/test/cases/oauth_case.rb b/test/cases/oauth_case.rb index 8c4d425d..2752b446 100644 --- a/test/cases/oauth_case.rb +++ b/test/cases/oauth_case.rb @@ -1,6 +1,6 @@ -require 'minitest/autorun' -require 'oauth/signature' -require 'oauth/request_proxy/mock_request' +require "minitest/autorun" +require "oauth/signature" +require "oauth/request_proxy/mock_request" class OAuthCase < Minitest::Test @@ -14,7 +14,7 @@ def run(*args) protected # Creates a fake request - def request(params={},method='GET',uri="http://photos.example.net/photos") - OAuth::RequestProxy.proxy({'parameters'=>params,'method'=>method,'uri'=>uri}) + def request(params={},method="GET",uri="http://photos.example.net/photos") + OAuth::RequestProxy.proxy({"parameters"=>params,"method"=>method,"uri"=>uri}) end end diff --git a/test/cases/spec/1_0-final/test_construct_request_url.rb b/test/cases/spec/1_0-final/test_construct_request_url.rb index 9a797c40..d9446622 100644 --- a/test/cases/spec/1_0-final/test_construct_request_url.rb +++ b/test/cases/spec/1_0-final/test_construct_request_url.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../oauth_case', __FILE__) +require File.expand_path("../../../oauth_case", __FILE__) # See http://oauth.net/core/1.0/#anchor14 # @@ -56,7 +56,7 @@ def test_of_https_with_non_standard_port def assert_request_url(expected,given,message=nil) - assert_equal expected, request({},'GET',given).normalized_uri, message + assert_equal expected, request({},"GET",given).normalized_uri, message end end diff --git a/test/cases/spec/1_0-final/test_normalize_request_parameters.rb b/test/cases/spec/1_0-final/test_normalize_request_parameters.rb index 91c93836..1054a54a 100644 --- a/test/cases/spec/1_0-final/test_normalize_request_parameters.rb +++ b/test/cases/spec/1_0-final/test_normalize_request_parameters.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../oauth_case', __FILE__) +require File.expand_path("../../../oauth_case", __FILE__) # See http://oauth.net/core/1.0/#anchor14 # @@ -34,16 +34,16 @@ def test_parameters_for_signature def test_parameters_for_signature_removes_oauth_signature params={"a"=>1, "c"=>"hi there", "f"=>"a", "z"=>"t"} - assert_equal params,request(params.merge({'oauth_signature'=>'blalbla'})).parameters_for_signature + assert_equal params,request(params.merge({"oauth_signature"=>"blalbla"})).parameters_for_signature end def test_spec_example - assert_normalized 'a=1&c=hi%20there&f=25&f=50&f=a&z=p&z=t', { 'a' => 1, 'c' => 'hi there', 'f' => ['25', '50', 'a'], 'z' => ['p', 't'] } + assert_normalized "a=1&c=hi%20there&f=25&f=50&f=a&z=p&z=t", { "a" => 1, "c" => "hi there", "f" => ["25", "50", "a"], "z" => ["p", "t"] } end def test_sorts_parameters_correctly # values for 'f' are scrambled - assert_normalized 'a=1&c=hi%20there&f=5&f=70&f=a&z=p&z=t', { 'a' => 1, 'c' => 'hi there', 'f' => ['a', '70', '5'], 'z' => ['p', 't'] } + assert_normalized "a=1&c=hi%20there&f=5&f=70&f=a&z=p&z=t", { "a" => 1, "c" => "hi there", "f" => ["a", "70", "5"], "z" => ["p", "t"] } end def test_empty @@ -59,20 +59,20 @@ def test_wiki1 end def test_wiki2 - assert_normalized "a=b",{'a'=>'b'} + assert_normalized "a=b",{"a"=>"b"} end def test_wiki3 - assert_normalized "a=b&c=d",{'a'=>'b','c'=>'d'} + assert_normalized "a=b&c=d",{"a"=>"b","c"=>"d"} end def test_wiki4 - assert_normalized "a=x%20y&a=x%21y",{'a'=>["x!y","x y"]} + assert_normalized "a=x%20y&a=x%21y",{"a"=>["x!y","x y"]} end def test_wiki5 - assert_normalized "x=a&x%21y=a",{"x!y"=>'a','x'=>'a'} + assert_normalized "x=a&x%21y=a",{"x!y"=>"a","x"=>"a"} end protected diff --git a/test/cases/spec/1_0-final/test_parameter_encodings.rb b/test/cases/spec/1_0-final/test_parameter_encodings.rb index db18fd86..d1885d5d 100644 --- a/test/cases/spec/1_0-final/test_parameter_encodings.rb +++ b/test/cases/spec/1_0-final/test_parameter_encodings.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../oauth_case', __FILE__) +require File.expand_path("../../../oauth_case", __FILE__) # See http://oauth.net/core/1.0/#encoding_parameters # @@ -14,51 +14,51 @@ class ParameterEncodingTest < OAuthCase def test_encodings_alpha_num - assert_encoding 'abcABC123', 'abcABC123' + assert_encoding "abcABC123", "abcABC123" end def test_encodings_non_escaped - assert_encoding '-._~', '-._~' + assert_encoding "-._~", "-._~" end def test_encodings_percent - assert_encoding '%25', '%' + assert_encoding "%25", "%" end def test_encodings_plus - assert_encoding '%2B', '+' + assert_encoding "%2B", "+" end def test_encodings_space - assert_encoding '%20', ' ' + assert_encoding "%20", " " end def test_encodings_query_param_symbols - assert_encoding '%26%3D%2A', '&=*' + assert_encoding "%26%3D%2A", "&=*" end def test_encodings_unicode_lf - assert_encoding '%0A', unicode_to_utf8('U+000A') + assert_encoding "%0A", unicode_to_utf8("U+000A") end def test_encodings_unicode_space - assert_encoding '%20', unicode_to_utf8('U+0020') + assert_encoding "%20", unicode_to_utf8("U+0020") end def test_encodings_unicode_007f - assert_encoding '%7F', unicode_to_utf8('U+007F') + assert_encoding "%7F", unicode_to_utf8("U+007F") end def test_encodings_unicode_0080 - assert_encoding '%C2%80', unicode_to_utf8('U+0080') + assert_encoding "%C2%80", unicode_to_utf8("U+0080") end def test_encoding_unicode_2708 - assert_encoding '%E2%9C%88', unicode_to_utf8('U+2708') + assert_encoding "%E2%9C%88", unicode_to_utf8("U+2708") end def test_encodings_unicode_3001 - assert_encoding '%E3%80%81', unicode_to_utf8('U+3001') + assert_encoding "%E3%80%81", unicode_to_utf8("U+3001") end protected @@ -66,12 +66,12 @@ def test_encodings_unicode_3001 def unicode_to_utf8(unicode) return unicode if unicode =~ /\A[[:space:]]*\z/m - str = '' + str = "" unicode.scan(/(U\+(?:[[:digit:][:xdigit:]]{4,5}|10[[:digit:][:xdigit:]]{4})|.)/mu) do c = $1 if c =~ /^U\+/ - str << [c[2..-1].hex].pack('U*') + str << [c[2..-1].hex].pack("U*") else str << c end diff --git a/test/cases/spec/1_0-final/test_signature_base_strings.rb b/test/cases/spec/1_0-final/test_signature_base_strings.rb index 6f6f7897..9f6ec1b4 100644 --- a/test/cases/spec/1_0-final/test_signature_base_strings.rb +++ b/test/cases/spec/1_0-final/test_signature_base_strings.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../oauth_case', __FILE__) +require File.expand_path("../../../oauth_case", __FILE__) # See http://oauth.net/core/1.0/#anchor14 # @@ -13,20 +13,20 @@ class SignatureBaseStringTest < OAuthCase - def test_A_5_1 + def test_a_5_1 parameters={ - 'oauth_consumer_key'=>'dpf43f3p2l4k3l03', - 'oauth_token'=>'nnch734d00sl2jdk', - 'oauth_signature_method'=>'HMAC-SHA1', - 'oauth_timestamp'=>'1191242096', - 'oauth_nonce'=>'kllo9940pd9333jh', - 'oauth_version'=>'1.0', - 'file'=>'vacation.jpg', - 'size'=>'original' + "oauth_consumer_key"=>"dpf43f3p2l4k3l03", + "oauth_token"=>"nnch734d00sl2jdk", + "oauth_signature_method"=>"HMAC-SHA1", + "oauth_timestamp"=>"1191242096", + "oauth_nonce"=>"kllo9940pd9333jh", + "oauth_version"=>"1.0", + "file"=>"vacation.jpg", + "size"=>"original" } - sbs='GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal' + sbs="GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal" - assert_signature_base_string sbs,parameters,'GET',"http://photos.example.net/photos" + assert_signature_base_string sbs,parameters,"GET","http://photos.example.net/photos" end # These are from the wiki http://wiki.oauth.net/TestCases @@ -34,44 +34,45 @@ def test_A_5_1 def test_wiki_1_simple_with_ending_slash parameters={ - 'n'=>'v' + "n"=>"v" } - sbs='GET&http%3A%2F%2Fexample.com%2F&n%3Dv' + sbs="GET&http%3A%2F%2Fexample.com%2F&n%3Dv" - assert_signature_base_string sbs,parameters,'GET',"http://example.com/" + assert_signature_base_string sbs,parameters,"GET","http://example.com/" end def test_wiki_2_simple_without_ending_slash parameters={ - 'n'=>'v' + "n"=>"v" } - sbs='GET&http%3A%2F%2Fexample.com%2F&n%3Dv' + sbs="GET&http%3A%2F%2Fexample.com%2F&n%3Dv" - assert_signature_base_string sbs,parameters,'GET',"http://example.com" + assert_signature_base_string sbs,parameters,"GET","http://example.com" end def test_wiki_2_request_token - parameters={ -'oauth_version'=>'1.0', -'oauth_consumer_key'=>'dpf43f3p2l4k3l03', -'oauth_timestamp'=>'1191242090', -'oauth_nonce'=>'hsu94j3884jdopsl', -'oauth_signature_method'=>'PLAINTEXT', -'oauth_signature'=>'ignored' } - sbs='POST&https%3A%2F%2Fphotos.example.net%2Frequest_token&oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dhsu94j3884jdopsl%26oauth_signature_method%3DPLAINTEXT%26oauth_timestamp%3D1191242090%26oauth_version%3D1.0' - - assert_signature_base_string sbs,parameters,'POST',"https://photos.example.net/request_token" + parameters = { + "oauth_version"=>"1.0", + "oauth_consumer_key"=>"dpf43f3p2l4k3l03", + "oauth_timestamp"=>"1191242090", + "oauth_nonce"=>"hsu94j3884jdopsl", + "oauth_signature_method"=>"PLAINTEXT", + "oauth_signature"=>"ignored" + } + sbs="POST&https%3A%2F%2Fphotos.example.net%2Frequest_token&oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dhsu94j3884jdopsl%26oauth_signature_method%3DPLAINTEXT%26oauth_timestamp%3D1191242090%26oauth_version%3D1.0" + + assert_signature_base_string sbs,parameters,"POST","https://photos.example.net/request_token" end protected - def assert_signature_base_string(expected,params={},method='GET',uri="http://photos.example.net/photos",message="Signature Base String does not match") + def assert_signature_base_string(expected,params={},method="GET",uri="http://photos.example.net/photos",message="Signature Base String does not match") assert_equal expected, signature_base_string(params,method,uri), message end - def signature_base_string(params={},method='GET',uri="http://photos.example.net/photos") + def signature_base_string(params={},method="GET",uri="http://photos.example.net/photos") request(params,method,uri).signature_base_string end end diff --git a/test/integration/consumer_test.rb b/test/integration/consumer_test.rb index 0aea36a8..bb7d9339 100644 --- a/test/integration/consumer_test.rb +++ b/test/integration/consumer_test.rb @@ -1,10 +1,10 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) module Integration class ConsumerTest < Minitest::Test def setup @consumer=OAuth::Consumer.new( - 'consumer_key_86cad9', '5888bf0345e5d237', + "consumer_key_86cad9", "5888bf0345e5d237", { :site=>"http://blabla.bla", :proxy=>"http://user:password@proxy.bla:8080", @@ -14,9 +14,9 @@ def setup :scheme=>:header, :http_method=>:get }) - @token = OAuth::ConsumerToken.new(@consumer,'token_411a7f', '3196ffd991c8ebdb') - @request_uri = URI.parse('http://example.com/test?key=value') - @request_parameters = { 'key' => 'value' } + @token = OAuth::ConsumerToken.new(@consumer,"token_411a7f", "3196ffd991c8ebdb") + @request_uri = URI.parse("http://example.com/test?key=value") + @request_parameters = { "key" => "value" } @nonce = 225579211881198842005988698334675835446 @timestamp = "1199645624" @consumer.http=Net::HTTP.new(@request_uri.host, @request_uri.port) @@ -26,30 +26,30 @@ def test_that_signing_auth_headers_on_get_requests_works request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s) @token.sign!(request, {:nonce => @nonce, :timestamp => @timestamp}) - assert_equal 'GET', request.method - assert_equal '/test?key=value', request.path - assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"1oO2izFav1GP4kEH2EskwXkCRFg%3D\", oauth_version=\"1.0\"".delete(',').split.sort, request['authorization'].delete(',').split.sort + assert_equal "GET", request.method + assert_equal "/test?key=value", request.path + assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"1oO2izFav1GP4kEH2EskwXkCRFg%3D\", oauth_version=\"1.0\"".delete(",").split.sort, request["authorization"].delete(",").split.sort end def test_that_setting_signature_method_on_consumer_effects_signing - require 'oauth/signature/plaintext' + require "oauth/signature/plaintext" request = Net::HTTP::Get.new(@request_uri.path) consumer = @consumer.dup - consumer.options[:signature_method] = 'PLAINTEXT' - token = OAuth::ConsumerToken.new(consumer, 'token_411a7f', '3196ffd991c8ebdb') + consumer.options[:signature_method] = "PLAINTEXT" + token = OAuth::ConsumerToken.new(consumer, "token_411a7f", "3196ffd991c8ebdb") token.sign!(request, {:nonce => @nonce, :timestamp => @timestamp}) - refute_match( /oauth_signature_method="HMAC-SHA1"/, request['authorization']) - assert_match( /oauth_signature_method="PLAINTEXT"/, request['authorization']) + refute_match( /oauth_signature_method="HMAC-SHA1"/, request["authorization"]) + assert_match( /oauth_signature_method="PLAINTEXT"/, request["authorization"]) end def test_that_setting_signature_method_on_consumer_effects_signature_base_string - require 'oauth/signature/plaintext' + require "oauth/signature/plaintext" request = Net::HTTP::Get.new(@request_uri.path) consumer = @consumer.dup - consumer.options[:signature_method] = 'PLAINTEXT' + consumer.options[:signature_method] = "PLAINTEXT" - request = Net::HTTP::Get.new('/') + request = Net::HTTP::Get.new("/") signature_base_string = consumer.signature_base_string(request) refute_match( /HMAC-SHA1/, signature_base_string) @@ -58,7 +58,7 @@ def test_that_setting_signature_method_on_consumer_effects_signature_base_string def test_that_plaintext_signature_works # Invalid test because server expects double-escaped signature - require 'oauth/signature/plaintext' + require "oauth/signature/plaintext" # consumer = OAuth::Consumer.new("key", "secret", # :site => "http://term.ie", :signature_method => 'PLAINTEXT') # access_token = OAuth::AccessToken.new(consumer, 'accesskey', 'accesssecret') @@ -73,46 +73,46 @@ def test_that_signing_auth_headers_on_post_requests_works @token.sign!(request, {:nonce => @nonce, :timestamp => @timestamp}) # assert_equal "",request.oauth_helper.signature_base_string - assert_equal 'POST', request.method - assert_equal '/test', request.path - assert_equal 'key=value', request.body - assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"26g7wHTtNO6ZWJaLltcueppHYiI%3D\", oauth_version=\"1.0\"".delete(',').split.sort, request['authorization'].delete(',').split.sort + assert_equal "POST", request.method + assert_equal "/test", request.path + assert_equal "key=value", request.body + assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"26g7wHTtNO6ZWJaLltcueppHYiI%3D\", oauth_version=\"1.0\"".delete(",").split.sort, request["authorization"].delete(",").split.sort end def test_that_signing_post_params_works request = Net::HTTP::Post.new(@request_uri.path) request.set_form_data( @request_parameters ) - @token.sign!(request, {:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp}) + @token.sign!(request, {:scheme => "body", :nonce => @nonce, :timestamp => @timestamp}) - assert_equal 'POST', request.method - assert_equal '/test', request.path + assert_equal "POST", request.method + assert_equal "/test", request.path assert_match(/key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=26g7wHTtNO6ZWJaLltcueppHYiI%3[Dd]&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0/, request.body.split("&").sort.join("&")) - assert_nil request['authorization'] + assert_nil request["authorization"] end def test_that_using_auth_headers_on_get_on_create_signed_requests_works request=@consumer.create_signed_request(:get,@request_uri.path+ "?" + request_parameters_to_s,@token,{:nonce => @nonce, :timestamp => @timestamp},@request_parameters) - assert_equal 'GET', request.method - assert_equal '/test?key=value', request.path - assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"1oO2izFav1GP4kEH2EskwXkCRFg%3D\", oauth_version=\"1.0\"".delete(',').split.sort, request['authorization'].delete(',').split.sort + assert_equal "GET", request.method + assert_equal "/test?key=value", request.path + assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"1oO2izFav1GP4kEH2EskwXkCRFg%3D\", oauth_version=\"1.0\"".delete(",").split.sort, request["authorization"].delete(",").split.sort end def test_that_using_auth_headers_on_post_on_create_signed_requests_works request=@consumer.create_signed_request(:post,@request_uri.path,@token,{:nonce => @nonce, :timestamp => @timestamp},@request_parameters,{}) - assert_equal 'POST', request.method - assert_equal '/test', request.path - assert_equal 'key=value', request.body - assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"26g7wHTtNO6ZWJaLltcueppHYiI%3D\", oauth_version=\"1.0\"".delete(',').split.sort, request['authorization'].delete(',').split.sort + assert_equal "POST", request.method + assert_equal "/test", request.path + assert_equal "key=value", request.body + assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"26g7wHTtNO6ZWJaLltcueppHYiI%3D\", oauth_version=\"1.0\"".delete(",").split.sort, request["authorization"].delete(",").split.sort end def test_that_signing_post_params_works_2 - request=@consumer.create_signed_request(:post,@request_uri.path,@token,{:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp},@request_parameters,{}) + request=@consumer.create_signed_request(:post,@request_uri.path,@token,{:scheme => "body", :nonce => @nonce, :timestamp => @timestamp},@request_parameters,{}) - assert_equal 'POST', request.method - assert_equal '/test', request.path + assert_equal "POST", request.method + assert_equal "/test", request.path assert_match(/key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=26g7wHTtNO6ZWJaLltcueppHYiI%3[Dd]&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0/, request.body.split("&").sort.join("&")) - assert_nil request['authorization'] + assert_nil request["authorization"] end def test_step_by_step_token_request @@ -128,14 +128,14 @@ def test_step_by_step_token_request :authorize_path=>"/oauth/example/authorize.php", :scheme=>:header }) - options={:nonce=>'nonce',:timestamp=>Time.now.to_i.to_s} + options={:nonce=>"nonce",:timestamp=>Time.now.to_i.to_s} request = Net::HTTP::Get.new("/oauth/example/request_token.php") signature_base_string=@consumer.signature_base_string(request,nil,options) assert_equal "GET&http%3A%2F%2Fterm.ie%2Foauth%2Fexample%2Frequest_token.php&oauth_consumer_key%3Dkey%26oauth_nonce%3D#{options[:nonce]}%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D#{options[:timestamp]}%26oauth_version%3D1.0",signature_base_string @consumer.sign!(request, nil,options) - assert_equal 'GET', request.method + assert_equal "GET", request.method assert_nil request.body response=@consumer.http.request(request) assert_equal "200",response.code @@ -177,7 +177,7 @@ def test_get_token_sequence assert_equal "200",@response.code assert_equal( "ok=hello&test=this",@response.body) - @response=@access_token.post("/oauth/example/echo_api.php",{'ok'=>'hello','test'=>'this'}) + @response=@access_token.post("/oauth/example/echo_api.php",{"ok"=>"hello","test"=>"this"}) assert @response assert_equal "200",@response.code assert_equal( "ok=hello&test=this",@response.body) @@ -218,7 +218,7 @@ def test_get_token_sequence_using_fqdn assert_equal "200",@response.code assert_equal( "ok=hello&test=this",@response.body) - @response=@access_token.post("/oauth/example/echo_api.php",{'ok'=>'hello','test'=>'this'}) + @response=@access_token.post("/oauth/example/echo_api.php",{"ok"=>"hello","test"=>"this"}) assert @response assert_equal "200",@response.code assert_equal( "ok=hello&test=this",@response.body) diff --git a/test/support/minitest_helpers.rb b/test/support/minitest_helpers.rb index d3ad41df..1f8d4e9a 100644 --- a/test/support/minitest_helpers.rb +++ b/test/support/minitest_helpers.rb @@ -2,10 +2,10 @@ module OAuth module MinitestHelpers def assert_matching_headers(expected, actual) # transform into sorted arrays - auth_intro, auth_params = actual.split(' ', 2) - assert_equal auth_intro, 'OAuth' - expected = expected.split(/(,|\s)/).reject {|v| v == '' || v =~ /^[\,\s]+/}.sort - auth_params = auth_params.split(/(,|\s)/).reject {|v| v == '' || v =~ /^[\,\s]+/}.sort + auth_intro, auth_params = actual.split(" ", 2) + assert_equal auth_intro, "OAuth" + expected = expected.split(/(,|\s)/).reject {|v| v == "" || v =~ /^[\,\s]+/}.sort + auth_params = auth_params.split(/(,|\s)/).reject {|v| v == "" || v =~ /^[\,\s]+/}.sort assert_equal expected, auth_params end diff --git a/test/test_helper.rb b/test/test_helper.rb index cae9399e..19e6cb9c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,6 @@ # ensure test env -ENV['RACK_ENV'] = 'test' +ENV["RACK_ENV"] = "test" # Code coverage require "simplecov" @@ -9,18 +9,18 @@ # require third-party code -require 'byebug' -require 'stringio' -require 'minitest/autorun' -require 'mocha/mini_test' -require 'rack/test' -require 'webmock/minitest' +require "byebug" +require "stringio" +require "minitest/autorun" +require "mocha/mini_test" +require "rack/test" +require "webmock/minitest" # require our lib -$LOAD_PATH << File.dirname(__FILE__) + '/../lib/' -require 'oauth' +$LOAD_PATH << File.dirname(__FILE__) + "/../lib/" +require "oauth" # require our support code -require 'support/minitest_helpers' +require "support/minitest_helpers" diff --git a/test/units/test_access_token.rb b/test/units/test_access_token.rb index ecd9a14a..1279acb8 100644 --- a/test/units/test_access_token.rb +++ b/test/units/test_access_token.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) class TestAccessToken < Minitest::Test def setup diff --git a/test/units/test_action_controller_request_proxy.rb b/test/units/test_action_controller_request_proxy.rb index 150ce78d..68905aab 100644 --- a/test/units/test_action_controller_request_proxy.rb +++ b/test/units/test_action_controller_request_proxy.rb @@ -1,138 +1,138 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) -require 'oauth/request_proxy/action_controller_request' +require "oauth/request_proxy/action_controller_request" class ActionControllerRequestProxyTest < Minitest::Test def request_proxy(request_method = :get, uri_params = {}, body_params = {}) request = ActionDispatch::TestRequest.create - request.request_uri = '/' + request.request_uri = "/" case request_method when :post - request.env['REQUEST_METHOD'] = 'POST' + request.env["REQUEST_METHOD"] = "POST" when :put - request.env['REQUEST_METHOD'] = 'PUT' + request.env["REQUEST_METHOD"] = "PUT" when :patch - request.env['REQUEST_METHOD'] = 'PATCH' + request.env["REQUEST_METHOD"] = "PATCH" end - request.env['REQUEST_URI'] = '/' - request.env['RAW_POST_DATA'] = body_params.to_query - request.env['QUERY_STRING'] = body_params.to_query - request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded' + request.env["REQUEST_URI"] = "/" + request.env["RAW_POST_DATA"] = body_params.to_query + request.env["QUERY_STRING"] = body_params.to_query + request.env["CONTENT_TYPE"] = "application/x-www-form-urlencoded" yield request if block_given? OAuth::RequestProxy::ActionControllerRequest.new(request, :parameters => uri_params) end def test_that_proxy_simple_get_request_works_with_query_params - request_proxy = request_proxy(:get, {'key'=>'value'}) + request_proxy = request_proxy(:get, {"key"=>"value"}) expected_parameters = [["key", "value"]] assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'GET', request_proxy.method + assert_equal "GET", request_proxy.method end def test_that_proxy_simple_post_request_works_with_query_params - request_proxy = request_proxy(:post, {'key'=>'value'}) + request_proxy = request_proxy(:post, {"key"=>"value"}) expected_parameters = [["key", "value"]] assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'POST', request_proxy.method + assert_equal "POST", request_proxy.method end def test_that_proxy_simple_put_request_works_with_query_params - request_proxy = request_proxy(:put, {'key'=>'value'}) + request_proxy = request_proxy(:put, {"key"=>"value"}) expected_parameters = [["key", "value"]] assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'PUT', request_proxy.method + assert_equal "PUT", request_proxy.method end def test_that_proxy_simple_patch_request_works_with_query_params - request_proxy = request_proxy(:patch, {'key'=>'value'}) + request_proxy = request_proxy(:patch, {"key"=>"value"}) expected_parameters = [["key", "value"]] assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'PATCH', request_proxy.method + assert_equal "PATCH", request_proxy.method end def test_that_proxy_simple_get_request_works_with_post_params - request_proxy = request_proxy(:get, {}, {'key'=>'value'}) + request_proxy = request_proxy(:get, {}, {"key"=>"value"}) expected_parameters = [] assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'GET', request_proxy.method + assert_equal "GET", request_proxy.method end def test_that_proxy_simple_post_request_works_with_post_params - request_proxy = request_proxy(:post, {}, {'key'=>'value'}) + request_proxy = request_proxy(:post, {}, {"key"=>"value"}) expected_parameters = [["key", "value"]] assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'POST', request_proxy.method + assert_equal "POST", request_proxy.method end def test_that_proxy_simple_put_request_works_with_post_params - request_proxy = request_proxy(:put, {}, {'key'=>'value'}) + request_proxy = request_proxy(:put, {}, {"key"=>"value"}) expected_parameters = [["key", "value"]] assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'PUT', request_proxy.method + assert_equal "PUT", request_proxy.method end def test_that_proxy_simple_patch_request_works_with_post_params - request_proxy = request_proxy(:patch, {}, {'key'=>'value'}) + request_proxy = request_proxy(:patch, {}, {"key"=>"value"}) expected_parameters = [] assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'PATCH', request_proxy.method + assert_equal "PATCH", request_proxy.method end def test_that_proxy_simple_get_request_works_with_mixed_params - request_proxy = request_proxy(:get, {'key'=>'value'}, {'key2'=>'value2'}) + request_proxy = request_proxy(:get, {"key"=>"value"}, {"key2"=>"value2"}) expected_parameters = [["key", "value"]] assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'GET', request_proxy.method + assert_equal "GET", request_proxy.method end def test_that_proxy_simple_post_request_works_with_mixed_params - request_proxy = request_proxy(:post, {'key'=>'value'}, {'key2'=>'value2'}) + request_proxy = request_proxy(:post, {"key"=>"value"}, {"key2"=>"value2"}) expected_parameters = [["key", "value"],["key2", "value2"]] assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'POST', request_proxy.method + assert_equal "POST", request_proxy.method end def test_that_proxy_simple_put_request_works_with_mixed_params - request_proxy = request_proxy(:put, {'key'=>'value'}, {'key2'=>'value2'}) + request_proxy = request_proxy(:put, {"key"=>"value"}, {"key2"=>"value2"}) expected_parameters = [["key", "value"],["key2", "value2"]] assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'PUT', request_proxy.method + assert_equal "PUT", request_proxy.method end def test_that_proxy_simple_patch_request_works_with_mixed_params - request_proxy = request_proxy(:patch, {'key'=>'value'}, {'key2'=>'value2'}) + request_proxy = request_proxy(:patch, {"key"=>"value"}, {"key2"=>"value2"}) expected_parameters = [["key", "value"]] assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'PATCH', request_proxy.method + assert_equal "PATCH", request_proxy.method end def test_parameter_keys_should_preserve_brackets_from_hash assert_equal( [["message[body]", "This is a test"]], - request_proxy(:post, { :message => { :body => 'This is a test' }}).parameters_for_signature + request_proxy(:post, { :message => { :body => "This is a test" }}).parameters_for_signature ) end def test_parameter_values_with_amps_should_not_break_parameter_parsing assert_equal( - [['message[body]', 'http://foo.com/?a=b&c=d']], - request_proxy(:post, { :message => { :body => 'http://foo.com/?a=b&c=d'}}).parameters_for_signature + [["message[body]", "http://foo.com/?a=b&c=d"]], + request_proxy(:post, { :message => { :body => "http://foo.com/?a=b&c=d"}}).parameters_for_signature ) end @@ -147,10 +147,10 @@ def test_parameter_keys_should_preserve_brackets_from_array # QUERY_STRING def x_test_query_string_parameter_values_should_be_cgi_unescaped request = request_proxy do |r| - r.env['QUERY_STRING'] = 'url=http%3A%2F%2Ffoo.com%2F%3Fa%3Db%26c%3Dd' + r.env["QUERY_STRING"] = "url=http%3A%2F%2Ffoo.com%2F%3Fa%3Db%26c%3Dd" end assert_equal( - [['url', 'http://foo.com/?a=b&c=d']], + [["url", "http://foo.com/?a=b&c=d"]], request.parameters_for_signature.sort ) end diff --git a/test/units/test_action_dispatch_request_proxy.rb b/test/units/test_action_dispatch_request_proxy.rb index 41f34484..1b91c561 100644 --- a/test/units/test_action_dispatch_request_proxy.rb +++ b/test/units/test_action_dispatch_request_proxy.rb @@ -1,39 +1,39 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) -require 'oauth/request_proxy/action_dispatch_request' +require "oauth/request_proxy/action_dispatch_request" class ActionRequestProxyTest < Minitest::Test def test_that_proxy_simple_get_request_works - request = ActionDispatch::Request.new(Rack::MockRequest.env_for('http://example.com/test?key=value')) - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value'}) + request = ActionDispatch::Request.new(Rack::MockRequest.env_for("http://example.com/test?key=value")) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test?key=value"}) - expected_parameters = {'key' => 'value'} + expected_parameters = {"key" => "value"} assert_equal expected_parameters, request_proxy.parameters - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'GET', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "GET", request_proxy.method end def test_that_proxy_simple_post_request_works - request = ActionDispatch::Request.new(Rack::MockRequest.env_for('http://example.com/test', :method => 'POST')) - params = {'key' => 'value'} - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params}) + request = ActionDispatch::Request.new(Rack::MockRequest.env_for("http://example.com/test", :method => "POST")) + params = {"key" => "value"} + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test", :parameters => params}) - expected_parameters = {'key' => 'value'} + expected_parameters = {"key" => "value"} assert_equal expected_parameters, request_proxy.parameters - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'POST', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "POST", request_proxy.method end def test_that_proxy_post_and_get_request_works - request = ActionDispatch::Request.new(Rack::MockRequest.env_for('http://example.com/test?key=value', :method => 'POST', :input => 'key2=value2')) - params = {'key2' => 'value2'} - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => params}) + request = ActionDispatch::Request.new(Rack::MockRequest.env_for("http://example.com/test?key=value", :method => "POST", :input => "key2=value2")) + params = {"key2" => "value2"} + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test?key=value", :parameters => params}) - expected_parameters = {'key' => 'value', 'key2' => 'value2'} + expected_parameters = {"key" => "value", "key2" => "value2"} assert_equal expected_parameters, request_proxy.parameters - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'POST', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "POST", request_proxy.method end end diff --git a/test/units/test_cli.rb b/test/units/test_cli.rb index 8129860d..1bd29ff1 100644 --- a/test/units/test_cli.rb +++ b/test/units/test_cli.rb @@ -1,46 +1,46 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) -require 'oauth/cli' +require "oauth/cli" class TestCLI < Minitest::Test def test_parse - assert_equal 'version', parse('-v') - assert_equal 'version', parse('--version') - - assert_equal 'help', parse('-h') - assert_equal 'help', parse('--help') - assert_equal 'help', parse('-H') - assert_equal 'help', parse('--HELP') - - assert_equal 'help', parse('') - assert_equal 'help', parse(nil) - - assert_equal 'help', parse('NotACommand') - - assert_equal 'help' , parse('h') - assert_equal 'version' , parse('v') - assert_equal 'query' , parse('q') - assert_equal 'authorize' , parse('a') - assert_equal 'sign' , parse('s') - - assert_equal 'help' , parse('help') - assert_equal 'version' , parse('version') - assert_equal 'query' , parse('query') - assert_equal 'authorize' , parse('authorize') - assert_equal 'sign' , parse('sign') - - assert_equal 'help' , parse('H') - assert_equal 'version' , parse('V') - assert_equal 'query' , parse('Q') - assert_equal 'authorize' , parse('A') - assert_equal 'sign' , parse('S') - - assert_equal 'help' , parse('HELP') - assert_equal 'version' , parse('VERSION') - assert_equal 'query' , parse('QUERY') - assert_equal 'authorize' , parse('AUTHORIZE') - assert_equal 'sign' , parse('SIGN') + assert_equal "version", parse("-v") + assert_equal "version", parse("--version") + + assert_equal "help", parse("-h") + assert_equal "help", parse("--help") + assert_equal "help", parse("-H") + assert_equal "help", parse("--HELP") + + assert_equal "help", parse("") + assert_equal "help", parse(nil) + + assert_equal "help", parse("NotACommand") + + assert_equal "help" , parse("h") + assert_equal "version" , parse("v") + assert_equal "query" , parse("q") + assert_equal "authorize" , parse("a") + assert_equal "sign" , parse("s") + + assert_equal "help" , parse("help") + assert_equal "version" , parse("version") + assert_equal "query" , parse("query") + assert_equal "authorize" , parse("authorize") + assert_equal "sign" , parse("sign") + + assert_equal "help" , parse("H") + assert_equal "version" , parse("V") + assert_equal "query" , parse("Q") + assert_equal "authorize" , parse("A") + assert_equal "sign" , parse("S") + + assert_equal "help" , parse("HELP") + assert_equal "version" , parse("VERSION") + assert_equal "query" , parse("QUERY") + assert_equal "authorize" , parse("AUTHORIZE") + assert_equal "sign" , parse("SIGN") end def test_help_empty @@ -86,28 +86,28 @@ def test_query consumer_new = lambda { |oauth_consumer_key, oauth_consumer_secret, options| expected_options = {:scheme=>:header} - assert_equal 'oauth_consumer_key', oauth_consumer_key - assert_equal 'oauth_consumer_secret', oauth_consumer_secret + assert_equal "oauth_consumer_key", oauth_consumer_key + assert_equal "oauth_consumer_secret", oauth_consumer_secret assert_equal expected_options, options consumer } access_token_new = lambda { |consumer1, token, secret| assert_equal consumer1.object_id, consumer.object_id - assert_equal 'TOKEN', token - assert_equal 'SECRET', secret + assert_equal "TOKEN", token + assert_equal "SECRET", secret access_token } # mock expects: # method return arguments #------------------------------------------------------------- - response.expect( :code , '!code!') - response.expect( :message , '!message!') - response.expect( :body , '!body!') + response.expect( :code , "!code!") + response.expect( :message , "!message!") + response.expect( :body , "!body!") access_token.expect(:request , response , [:post, "http://example.com/oauth/url?oauth_consumer_key=oauth_consumer_key&oauth_nonce=GENERATE_KEY&oauth_timestamp=GENERATE_TIMESTAMP&oauth_token=TOKEN&oauth_signature_method=HMAC-SHA1&oauth_version=1.0"]) - OAuth::Helper.stub(:generate_key, 'GENERATE_KEY') do - OAuth::Helper.stub(:generate_timestamp, 'GENERATE_TIMESTAMP') do + OAuth::Helper.stub(:generate_key, "GENERATE_KEY") do + OAuth::Helper.stub(:generate_timestamp, "GENERATE_TIMESTAMP") do OAuth::AccessToken.stub(:new, access_token_new) do OAuth::Consumer.stub(:new, consumer_new) do out = run_command %w[query @@ -136,8 +136,8 @@ def test_authorize consumer_new = lambda { |oauth_consumer_key, oauth_consumer_secret, options| expected_options = {:access_token_url=>nil, :authorize_url=>nil, :request_token_url=>nil, :scheme=>:header, :http_method=>:get} - assert_equal 'oauth_consumer_key', oauth_consumer_key - assert_equal 'oauth_consumer_secret', oauth_consumer_secret + assert_equal "oauth_consumer_key", oauth_consumer_key + assert_equal "oauth_consumer_secret", oauth_consumer_secret assert_equal expected_options, options consumer } @@ -151,8 +151,8 @@ def test_authorize request_token.expect( :authorize_url , "!url1!") request_token.expect( :get_access_token , access_token, [{:oauth_verifier=>nil}]) - OAuth::Helper.stub(:generate_key, 'GENERATE_KEY') do - OAuth::Helper.stub(:generate_timestamp, 'GENERATE_TIMESTAMP') do + OAuth::Helper.stub(:generate_key, "GENERATE_KEY") do + OAuth::Helper.stub(:generate_timestamp, "GENERATE_TIMESTAMP") do OAuth::Consumer.stub(:new, consumer_new) do out = run_command %w[authorize @@ -180,8 +180,8 @@ def test_sign consumer_new = lambda { |oauth_consumer_key, oauth_consumer_secret, options| expected_options = {:access_token_url=>nil, :authorize_url=>nil, :request_token_url=>nil, :scheme=>:header, :http_method=>:get} - assert_equal 'oauth_consumer_key', oauth_consumer_key - assert_equal 'oauth_consumer_secret', oauth_consumer_secret + assert_equal "oauth_consumer_key", oauth_consumer_key + assert_equal "oauth_consumer_secret", oauth_consumer_secret assert_equal expected_options, options consumer } @@ -197,8 +197,8 @@ def test_sign out = [] - OAuth::Helper.stub(:generate_key, 'GENERATE_KEY') do - OAuth::Helper.stub(:generate_timestamp, 'GENERATE_TIMESTAMP') do + OAuth::Helper.stub(:generate_key, "GENERATE_KEY") do + OAuth::Helper.stub(:generate_timestamp, "GENERATE_TIMESTAMP") do OAuth::Consumer.stub(:new, consumer_new) do out.push run_command %w[sign diff --git a/test/units/test_client_helper.rb b/test/units/test_client_helper.rb index d6ed973a..18851401 100644 --- a/test/units/test_client_helper.rb +++ b/test/units/test_client_helper.rb @@ -1,12 +1,12 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) -require 'oauth/client' +require "oauth/client" class ClientHelperTest < Minitest::Test def setup @consumer=OAuth::Consumer.new( - 'consumer_key_86cad9', '5888bf0345e5d237', + "consumer_key_86cad9", "5888bf0345e5d237", { :site=>"http://blabla.bla", :proxy=>"http://user:password@proxy.bla:8080", @@ -22,8 +22,8 @@ def test_oauth_parameters_allow_empty_params_default helper = OAuth::Client::Helper.new(nil, { :consumer => @consumer }) - helper.stub :timestamp, '0' do - helper.stub :nonce, 'nonce' do + helper.stub :timestamp, "0" do + helper.stub :nonce, "nonce" do expected = { "oauth_consumer_key"=>"consumer_key_86cad9", "oauth_signature_method"=>"HMAC-SHA1", @@ -42,8 +42,8 @@ def test_oauth_parameters_allow_empty_params_true :consumer => @consumer, :allow_empty_params => input }) - helper.stub :timestamp, '0' do - helper.stub :nonce, 'nonce' do + helper.stub :timestamp, "0" do + helper.stub :nonce, "nonce" do expected = { "oauth_body_hash"=>nil, "oauth_callback"=>nil, @@ -67,8 +67,8 @@ def test_oauth_parameters_allow_empty_params_false :consumer => @consumer, :allow_empty_params => input }) - helper.stub :timestamp, '0' do - helper.stub :nonce, 'nonce' do + helper.stub :timestamp, "0" do + helper.stub :nonce, "nonce" do expected = { "oauth_consumer_key"=>"consumer_key_86cad9", "oauth_signature_method"=>"HMAC-SHA1", @@ -82,13 +82,13 @@ def test_oauth_parameters_allow_empty_params_false end def test_oauth_parameters_allow_empty_params_only_oauth_token_as_string - input = 'oauth_token' + input = "oauth_token" helper = OAuth::Client::Helper.new(nil, { :consumer => @consumer, :allow_empty_params => input }) - helper.stub :timestamp, '0' do - helper.stub :nonce, 'nonce' do + helper.stub :timestamp, "0" do + helper.stub :nonce, "nonce" do expected = { "oauth_consumer_key"=>"consumer_key_86cad9", "oauth_token"=>"", @@ -103,13 +103,13 @@ def test_oauth_parameters_allow_empty_params_only_oauth_token_as_string end def test_oauth_parameters_allow_empty_params_only_oauth_token_as_array - input = ['oauth_token'] + input = ["oauth_token"] helper = OAuth::Client::Helper.new(nil, { :consumer => @consumer, :allow_empty_params => input }) - helper.stub :timestamp, '0' do - helper.stub :nonce, 'nonce' do + helper.stub :timestamp, "0" do + helper.stub :nonce, "nonce" do expected = { "oauth_consumer_key"=>"consumer_key_86cad9", "oauth_token"=>"", @@ -124,13 +124,13 @@ def test_oauth_parameters_allow_empty_params_only_oauth_token_as_array end def test_oauth_parameters_allow_empty_params_oauth_token_and_oauth_session_handle - input = ['oauth_token', 'oauth_session_handle'] + input = ["oauth_token", "oauth_session_handle"] helper = OAuth::Client::Helper.new(nil, { :consumer => @consumer, :allow_empty_params => input }) - helper.stub :timestamp, '0' do - helper.stub :nonce, 'nonce' do + helper.stub :timestamp, "0" do + helper.stub :nonce, "nonce" do expected = { "oauth_consumer_key"=>"consumer_key_86cad9", "oauth_token"=>"", diff --git a/test/units/test_consumer.rb b/test/units/test_consumer.rb index 8c58674f..869d0289 100644 --- a/test/units/test_consumer.rb +++ b/test/units/test_consumer.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) # This performs testing against Andy Smith's test server http://term.ie/oauth/example/ # Thanks Andy. @@ -6,7 +6,7 @@ class ConsumerTest < Minitest::Test def setup @consumer=OAuth::Consumer.new( - 'consumer_key_86cad9', '5888bf0345e5d237', + "consumer_key_86cad9", "5888bf0345e5d237", { :site=>"http://blabla.bla", :proxy=>"http://user:password@proxy.bla:8080", @@ -16,9 +16,9 @@ def setup :scheme=>:header, :http_method=>:get }) - @token = OAuth::ConsumerToken.new(@consumer,'token_411a7f', '3196ffd991c8ebdb') - @request_uri = URI.parse('http://example.com/test?key=value') - @request_parameters = { 'key' => 'value' } + @token = OAuth::ConsumerToken.new(@consumer,"token_411a7f", "3196ffd991c8ebdb") + @request_uri = URI.parse("http://example.com/test?key=value") + @request_parameters = { "key" => "value" } @nonce = 225579211881198842005988698334675835446 @timestamp = "1199645624" @consumer.http=Net::HTTP.new(@request_uri.host, @request_uri.port) @@ -90,9 +90,9 @@ def test_site_without_path }) request = stub(:oauth! => nil) http = stub(:request => stub(:to_hash => {}), :address => "identi.ca") - Net::HTTP::Get.expects(:new).with('/people', {}).returns(request) + Net::HTTP::Get.expects(:new).with("/people", {}).returns(request) @consumer.expects(:create_http).returns(http) - @consumer.request(:get, '/people', nil, {}) + @consumer.request(:get, "/people", nil, {}) end def test_site_with_path @@ -104,9 +104,9 @@ def test_site_with_path }) request = stub(:oauth! => nil) http = stub(:request => stub(:to_hash => {}), :address => "identi.ca") - Net::HTTP::Get.expects(:new).with('/api/people', {}).returns(request) + Net::HTTP::Get.expects(:new).with("/api/people", {}).returns(request) @consumer.expects(:create_http).returns(http) - @consumer.request(:get, '/people', nil, {}) + @consumer.request(:get, "/people", nil, {}) end def test_post_of_nested_params_maintains_nesting @@ -118,16 +118,16 @@ def test_post_of_nested_params_maintains_nesting }) request = @consumer.create_signed_request( :post, - '/people', + "/people", nil, {}, { :key => { - :subkey => 'value' + :subkey => "value" } }) - assert_equal 'key%5Bsubkey%5D=value', request.body - assert_equal request.content_type, 'application/x-www-form-urlencoded' + assert_equal "key%5Bsubkey%5D=value", request.body + assert_equal request.content_type, "application/x-www-form-urlencoded" end def test_override_paths @@ -216,7 +216,7 @@ def test_noverify_empty def test_token_request_identifies_itself_as_a_token_request request_options = {} @consumer.stubs(:request).returns(create_stub_http_response) - @consumer.token_request(:post, '/', 'token', request_options) {} + @consumer.token_request(:post, "/", "token", request_options) {} assert_equal true, request_options[:token_request] end @@ -232,44 +232,44 @@ def test_that_token_response_should_be_uri_parameter_format_as_default def test_can_provided_a_block_to_interpret_token_response @consumer.expects(:request).returns(create_stub_http_response) - hash = @consumer.token_request(:get, '') {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }} + hash = @consumer.token_request(:get, "") {{ :oauth_token => "token", :oauth_token_secret => "secret" }} - assert_equal 'token', hash[:oauth_token] - assert_equal 'secret', hash[:oauth_token_secret] + assert_equal "token", hash[:oauth_token] + assert_equal "secret", hash[:oauth_token_secret] end def test_token_request_follows_redirect redirect_url = @request_uri.clone redirect_url.path = "/oauth/example/request_token_redirect.php" - stub_request(:get, /.*#{@request_uri.path}/).to_return(:status => 301, :headers => {'Location' => redirect_url.to_s}) + stub_request(:get, /.*#{@request_uri.path}/).to_return(:status => 301, :headers => {"Location" => redirect_url.to_s}) stub_request(:get, /.*#{redirect_url.path}/).to_return(:body => "oauth_token=token&oauth_token_secret=secret") - hash = @consumer.token_request(:get, @request_uri.path) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }} + hash = @consumer.token_request(:get, @request_uri.path) {{ :oauth_token => "token", :oauth_token_secret => "secret" }} - assert_equal 'token', hash[:oauth_token] - assert_equal 'secret', hash[:oauth_token_secret] + assert_equal "token", hash[:oauth_token] + assert_equal "secret", hash[:oauth_token_secret] end def test_follow_redirect_different_host_same_path request_uri = URI.parse("https://example.com/request_token") redirect_uri = URI.parse("https://foobar.com/request_token") - stub_request(:get, "http://example.com/request_token").to_return(:status => 301, :headers => {'Location' => redirect_uri.to_s}) + stub_request(:get, "http://example.com/request_token").to_return(:status => 301, :headers => {"Location" => redirect_uri.to_s}) stub_request(:get, "https://foobar.com/request_token").to_return(:body => "oauth_token=token&oauth_token_secret=secret") - hash = @consumer.token_request(:get, request_uri.path) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }} + hash = @consumer.token_request(:get, request_uri.path) {{ :oauth_token => "token", :oauth_token_secret => "secret" }} - assert_equal 'token', hash[:oauth_token] - assert_equal 'secret', hash[:oauth_token_secret] + assert_equal "token", hash[:oauth_token] + assert_equal "secret", hash[:oauth_token_secret] end def test_that_can_provide_a_block_to_interpret_a_request_token_response @consumer.expects(:request).returns(create_stub_http_response) - token = @consumer.get_request_token {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }} + token = @consumer.get_request_token {{ :oauth_token => "token", :oauth_token_secret => "secret" }} - assert_equal 'token', token.token - assert_equal 'secret', token.secret + assert_equal "token", token.token + assert_equal "secret", token.secret end def test_that_block_is_not_mandatory_for_getting_an_access_token @@ -278,34 +278,34 @@ def test_that_block_is_not_mandatory_for_getting_an_access_token token = @consumer.get_access_token(stub_token) - assert_equal 'token', token.token - assert_equal 'secret', token.secret + assert_equal "token", token.token + assert_equal "secret", token.secret end def test_that_can_provide_a_block_to_interpret_an_access_token_response stub_token = mock @consumer.expects(:request).returns(create_stub_http_response) - token = @consumer.get_access_token(stub_token) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }} + token = @consumer.get_access_token(stub_token) {{ :oauth_token => "token", :oauth_token_secret => "secret" }} - assert_equal 'token', token.token - assert_equal 'secret', token.secret + assert_equal "token", token.token + assert_equal "secret", token.secret end def test_that_not_setting_ignore_callback_will_include_oauth_callback_in_request_options request_options = {} @consumer.stubs(:request).returns(create_stub_http_response) - @consumer.get_request_token(request_options) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }} + @consumer.get_request_token(request_options) {{ :oauth_token => "token", :oauth_token_secret => "secret" }} - assert_equal 'oob', request_options[:oauth_callback] + assert_equal "oob", request_options[:oauth_callback] end def test_that_setting_ignore_callback_will_exclude_oauth_callback_in_request_options request_options = { :exclude_callback=> true } @consumer.stubs(:request).returns(create_stub_http_response) - @consumer.get_request_token(request_options) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }} + @consumer.get_request_token(request_options) {{ :oauth_token => "token", :oauth_token_secret => "secret" }} assert_nil request_options[:oauth_callback] end diff --git a/test/units/test_curb_request_proxy.rb b/test/units/test_curb_request_proxy.rb index 4f34b773..1015df4e 100644 --- a/test/units/test_curb_request_proxy.rb +++ b/test/units/test_curb_request_proxy.rb @@ -1,74 +1,74 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) begin -require 'oauth/request_proxy/curb_request' -require 'curb' +require "oauth/request_proxy/curb_request" +require "curb" class CurbRequestProxyTest < Minitest::Test def test_that_proxy_simple_get_request_works - request = Curl::Easy.new('/test?key=value') - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value'}) + request = Curl::Easy.new("/test?key=value") + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test?key=value"}) - expected_parameters = {'key' => ['value']} + expected_parameters = {"key" => ["value"]} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri + assert_equal "http://example.com/test", request_proxy.normalized_uri end def test_that_proxy_simple_post_request_works_with_arguments - request = Curl::Easy.new('/test') - params = {'key' => 'value'} - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params}) + request = Curl::Easy.new("/test") + params = {"key" => "value"} + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test", :parameters => params}) - expected_parameters = {'key' => 'value'} + expected_parameters = {"key" => "value"} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri + assert_equal "http://example.com/test", request_proxy.normalized_uri end def test_that_proxy_simple_post_request_works_with_form_data - request = Curl::Easy.new('/test') - request.post_body = 'key=value' - request.headers['Content-Type'] = 'application/x-www-form-urlencoded' + request = Curl::Easy.new("/test") + request.post_body = "key=value" + request.headers["Content-Type"] = "application/x-www-form-urlencoded" - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'}) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test"}) - expected_parameters = {'key' => 'value'} + expected_parameters = {"key" => "value"} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri + assert_equal "http://example.com/test", request_proxy.normalized_uri end def test_that_proxy_simple_put_request_works_with_arguments - request = Curl::Easy.new('/test') - params = {'key' => 'value'} - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params}) + request = Curl::Easy.new("/test") + params = {"key" => "value"} + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test", :parameters => params}) - expected_parameters = {'key' => 'value'} + expected_parameters = {"key" => "value"} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri + assert_equal "http://example.com/test", request_proxy.normalized_uri end def test_that_proxy_simple_put_request_works_with_form_data - request = Curl::Easy.new('/test') - request.post_body = 'key=value' + request = Curl::Easy.new("/test") + request.post_body = "key=value" - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'}) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test"}) expected_parameters = {} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri + assert_equal "http://example.com/test", request_proxy.normalized_uri end def test_that_proxy_post_request_works_with_mixed_parameter_sources - request = Curl::Easy.new('/test?key=value') - request.post_body = 'key2=value2' - request.headers['Content-Type'] = 'application/x-www-form-urlencoded' - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => {'key3' => 'value3'}}) + request = Curl::Easy.new("/test?key=value") + request.post_body = "key2=value2" + request.headers["Content-Type"] = "application/x-www-form-urlencoded" + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test?key=value", :parameters => {"key3" => "value3"}}) - expected_parameters = {'key' => ['value'], 'key2' => 'value2', 'key3' => 'value3'} + expected_parameters = {"key" => ["value"], "key2" => "value2", "key3" => "value3"} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri + assert_equal "http://example.com/test", request_proxy.normalized_uri end end diff --git a/test/units/test_em_http_client.rb b/test/units/test_em_http_client.rb index 37466160..a2e68a64 100644 --- a/test/units/test_em_http_client.rb +++ b/test/units/test_em_http_client.rb @@ -1,15 +1,15 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) begin -require 'oauth/client/em_http' +require "oauth/client/em_http" class EmHttpClientTest < Minitest::Test def setup - @consumer = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237') - @token = OAuth::Token.new('token_411a7f', '3196ffd991c8ebdb') - @request_uri = URI.parse('http://example.com/test?key=value') - @request_parameters = { 'key' => 'value' } + @consumer = OAuth::Consumer.new("consumer_key_86cad9", "5888bf0345e5d237") + @token = OAuth::Token.new("token_411a7f", "3196ffd991c8ebdb") + @request_uri = URI.parse("http://example.com/test?key=value") + @request_parameters = { "key" => "value" } @nonce = 225579211881198842005988698334675835446 @timestamp = "1199645624" # This is really unneeded I guess. @@ -20,8 +20,8 @@ def test_that_using_auth_headers_on_get_requests_works request = create_client request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp}) - assert_equal 'GET', request.req[:method] - assert_equal '/test', request.normalize_uri.path + assert_equal "GET", request.req[:method] + assert_equal "/test", request.normalize_uri.path assert_equal "key=value", request.normalize_uri.query correct_headers = "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"1oO2izFav1GP4kEH2EskwXkCRFg%3D\", oauth_version=\"1.0\"" generated_headers = authz_header(request) @@ -29,15 +29,15 @@ def test_that_using_auth_headers_on_get_requests_works end def test_that_using_auth_headers_on_get_requests_works_with_plaintext - require 'oauth/signature/plaintext' - c = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237',{ - :signature_method => 'PLAINTEXT' + require "oauth/signature/plaintext" + c = OAuth::Consumer.new("consumer_key_86cad9", "5888bf0345e5d237",{ + :signature_method => "PLAINTEXT" }) request = create_client - request.oauth!(@http, c, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'}) + request.oauth!(@http, c, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => "PLAINTEXT"}) - assert_equal 'GET', request.req[:method] - assert_equal '/test', request.conn.path + assert_equal "GET", request.req[:method] + assert_equal "/test", request.conn.path assert_equal "key=value", request.conn.query assert_equal_authz_headers "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"PLAINTEXT\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"5888bf0345e5d237%263196ffd991c8ebdb\", oauth_version=\"1.0\"", authz_header(request) end @@ -46,10 +46,10 @@ def test_that_using_auth_headers_on_post_requests_works request = create_client(:uri => "http://example.com/test", :method => "POST", :body => @request_parameters, :head => {"Content-Type" => "application/x-www-form-urlencoded"}) request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp}) - assert_equal 'POST', request.req[:method] - assert_equal '/test', request.conn.path + assert_equal "POST", request.req[:method] + assert_equal "/test", request.conn.path assert_equal_authz_headers "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"26g7wHTtNO6ZWJaLltcueppHYiI%3D\", oauth_version=\"1.0\"", authz_header(request) - assert_equal 'key=value', request.normalize_body(request.req[:body]) + assert_equal "key=value", request.normalize_body(request.req[:body]) end protected @@ -61,13 +61,13 @@ def create_client(options = {}) end def authz_header(request) - request.req[:head]['Authorization'] + request.req[:head]["Authorization"] end def assert_equal_authz_headers(expected, actual) assert !actual.nil? assert_equal expected[0,6], actual[0, 6] - assert_equal expected[6..1].split(', ').sort, actual[6..1].split(', ').sort + assert_equal expected[6..1].split(", ").sort, actual[6..1].split(", ").sort end end diff --git a/test/units/test_em_http_request_proxy.rb b/test/units/test_em_http_request_proxy.rb index e7a07718..850a72f1 100644 --- a/test/units/test_em_http_request_proxy.rb +++ b/test/units/test_em_http_request_proxy.rb @@ -1,9 +1,9 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) begin -require 'em-http' -require 'oauth/request_proxy/em_http_request' +require "em-http" +require "oauth/request_proxy/em_http_request" class EmHttpRequestProxyTest < Minitest::Test @@ -20,47 +20,47 @@ def test_request_proxy_works_with_query_string_params end def test_request_proxy_works_with_post_body_params_with_correct_content_type - proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "POST" + proxy = create_request_proxy :head => {"Content-Type" => "application/x-www-form-urlencoded"}, :method => "POST" assert_equal({}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "POST", :body => "a=1" + proxy = create_request_proxy :head => {"Content-Type" => "application/x-www-form-urlencoded"}, :method => "POST", :body => "a=1" assert_equal({"a" => ["1"]}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "POST", :body => {"a" => 1} + proxy = create_request_proxy :head => {"Content-Type" => "application/x-www-form-urlencoded"}, :method => "POST", :body => {"a" => 1} assert_equal({"a" => ["1"]}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "PUT" + proxy = create_request_proxy :head => {"Content-Type" => "application/x-www-form-urlencoded"}, :method => "PUT" assert_equal({}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "PUT", :body => "a=1" + proxy = create_request_proxy :head => {"Content-Type" => "application/x-www-form-urlencoded"}, :method => "PUT", :body => "a=1" assert_equal({"a" => ["1"]}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "PUT", :body => {"a" => 1} + proxy = create_request_proxy :head => {"Content-Type" => "application/x-www-form-urlencoded"}, :method => "PUT", :body => {"a" => 1} assert_equal({"a" => ["1"]}, proxy.parameters) end def test_request_proxy_ignore_post_body_with_invalid_content_type - proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "POST" + proxy = create_request_proxy :head => {"Content-Type" => "text/plain"}, :method => "POST" assert_equal({}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "POST", :body => "a=1" + proxy = create_request_proxy :head => {"Content-Type" => "text/plain"}, :method => "POST", :body => "a=1" assert_equal({}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "POST", :body => {"a" => 1} + proxy = create_request_proxy :head => {"Content-Type" => "text/plain"}, :method => "POST", :body => {"a" => 1} assert_equal({}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "PUT" + proxy = create_request_proxy :head => {"Content-Type" => "text/plain"}, :method => "PUT" assert_equal({}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "PUT", :body => "a=1" + proxy = create_request_proxy :head => {"Content-Type" => "text/plain"}, :method => "PUT", :body => "a=1" assert_equal({}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "PUT", :body => {"a" => 1} + proxy = create_request_proxy :head => {"Content-Type" => "text/plain"}, :method => "PUT", :body => {"a" => 1} assert_equal({}, proxy.parameters) end def test_request_proxy_ignores_post_body_with_invalid_method - proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "DELETE" + proxy = create_request_proxy :head => {"Content-Type" => "application/x-www-form-urlencoded"}, :method => "DELETE" assert_equal({}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "DELETE", :body => "a=1" + proxy = create_request_proxy :head => {"Content-Type" => "application/x-www-form-urlencoded"}, :method => "DELETE", :body => "a=1" assert_equal({}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "DELETE", :body => {"a" => 1} + proxy = create_request_proxy :head => {"Content-Type" => "application/x-www-form-urlencoded"}, :method => "DELETE", :body => {"a" => 1} assert_equal({}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "GET" + proxy = create_request_proxy :head => {"Content-Type" => "application/x-www-form-urlencoded"}, :method => "GET" assert_equal({}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "GET", :body => "a=1" + proxy = create_request_proxy :head => {"Content-Type" => "application/x-www-form-urlencoded"}, :method => "GET", :body => "a=1" assert_equal({}, proxy.parameters) - proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "GET", :body => {"a" => 1} + proxy = create_request_proxy :head => {"Content-Type" => "application/x-www-form-urlencoded"}, :method => "GET", :body => {"a" => 1} assert_equal({}, proxy.parameters) end diff --git a/test/units/test_hmac_sha1.rb b/test/units/test_hmac_sha1.rb index e71904b2..f3c6fb1f 100644 --- a/test/units/test_hmac_sha1.rb +++ b/test/units/test_hmac_sha1.rb @@ -1,20 +1,20 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) class TestSignatureHmacSha1 < Minitest::Test def test_that_hmac_sha1_implements_hmac_sha1 - assert OAuth::Signature.available_methods.include?('hmac-sha1') + assert OAuth::Signature.available_methods.include?("hmac-sha1") end def test_that_get_request_from_oauth_test_cases_produces_matching_signature - request = Net::HTTP::Get.new('/photos?file=vacation.jpg&size=original&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk&oauth_timestamp=1191242096&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1') + request = Net::HTTP::Get.new("/photos?file=vacation.jpg&size=original&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk&oauth_timestamp=1191242096&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1") - consumer = OAuth::Consumer.new('dpf43f3p2l4k3l03', 'kd94hf93k423kf44') - token = OAuth::Token.new('nnch734d00sl2jdk', 'pfkkdhi9sl3r4s00') + consumer = OAuth::Consumer.new("dpf43f3p2l4k3l03", "kd94hf93k423kf44") + token = OAuth::Token.new("nnch734d00sl2jdk", "pfkkdhi9sl3r4s00") signature = OAuth::Signature.sign(request, { :consumer => consumer, :token => token, - :uri => 'http://photos.example.net/photos' } ) + :uri => "http://photos.example.net/photos" } ) - assert_equal 'tR3+Ty81lMeYAr/Fid0kMTYa/WM=', signature + assert_equal "tR3+Ty81lMeYAr/Fid0kMTYa/WM=", signature end end diff --git a/test/units/test_hmac_sha256.rb b/test/units/test_hmac_sha256.rb index 58e5bd86..2a660f05 100644 --- a/test/units/test_hmac_sha256.rb +++ b/test/units/test_hmac_sha256.rb @@ -1,21 +1,21 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) class TestSignatureHmacSha256 < Minitest::Test def test_that_hmac_sha256_implements_hmac_sha256 - assert OAuth::Signature.available_methods.include?('hmac-sha256') + assert OAuth::Signature.available_methods.include?("hmac-sha256") end def test_that_get_request_from_oauth_test_cases_produces_matching_signature - request = Net::HTTP::Get.new('/photos?file=vacation.jpg&size=original&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk&oauth_timestamp=1191242096&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA256') + request = Net::HTTP::Get.new("/photos?file=vacation.jpg&size=original&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk&oauth_timestamp=1191242096&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA256") - consumer = OAuth::Consumer.new('dpf43f3p2l4k3l03', 'kd94hf93k423kf44') - token = OAuth::Token.new('nnch734d00sl2jdk', 'pfkkdhi9sl3r4s00') + consumer = OAuth::Consumer.new("dpf43f3p2l4k3l03", "kd94hf93k423kf44") + token = OAuth::Token.new("nnch734d00sl2jdk", "pfkkdhi9sl3r4s00") signature = OAuth::Signature.sign(request, { :consumer => consumer, :token => token, - :uri => 'http://photos.example.net/photos', - :signature_method => 'HMAC-SHA256' } ) + :uri => "http://photos.example.net/photos", + :signature_method => "HMAC-SHA256" } ) - assert_equal 'WVPzl1j6ZsnkIjWr7e3OZ3jkenL57KwaLFhYsroX1hg=', signature + assert_equal "WVPzl1j6ZsnkIjWr7e3OZ3jkenL57KwaLFhYsroX1hg=", signature end end diff --git a/test/units/test_net_http_client.rb b/test/units/test_net_http_client.rb index aa327928..0148f9d5 100644 --- a/test/units/test_net_http_client.rb +++ b/test/units/test_net_http_client.rb @@ -1,12 +1,12 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) class NetHTTPClientTest < Minitest::Test def setup - @consumer = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237') - @token = OAuth::Token.new('token_411a7f', '3196ffd991c8ebdb') - @request_uri = URI.parse('http://example.com/test?key=value') - @request_parameters = { 'key' => 'value' } + @consumer = OAuth::Consumer.new("consumer_key_86cad9", "5888bf0345e5d237") + @token = OAuth::Token.new("token_411a7f", "3196ffd991c8ebdb") + @request_uri = URI.parse("http://example.com/test?key=value") + @request_parameters = { "key" => "value" } @nonce = 225579211881198842005988698334675835446 @timestamp = "1199645624" @http = Net::HTTP.new(@request_uri.host, @request_uri.port) @@ -16,25 +16,25 @@ def test_that_using_auth_headers_on_get_requests_works request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s) request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp}) - assert_equal 'GET', request.method - assert_equal '/test?key=value', request.path + assert_equal "GET", request.method + assert_equal "/test?key=value", request.path correct_sorted_params = "oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"1oO2izFav1GP4kEH2EskwXkCRFg%3D\", oauth_version=\"1.0\"" - auth_intro = request['authorization'].split(' ', 2).first - assert_equal auth_intro, 'OAuth' - assert_matching_headers correct_sorted_params, request['authorization'] + auth_intro = request["authorization"].split(" ", 2).first + assert_equal auth_intro, "OAuth" + assert_matching_headers correct_sorted_params, request["authorization"] end def test_that_using_auth_headers_on_get_requests_works_with_plaintext - require 'oauth/signature/plaintext' - c = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237',{ - :signature_method => 'PLAINTEXT' + require "oauth/signature/plaintext" + c = OAuth::Consumer.new("consumer_key_86cad9", "5888bf0345e5d237",{ + :signature_method => "PLAINTEXT" }) request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s) - request.oauth!(@http, c, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'}) + request.oauth!(@http, c, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => "PLAINTEXT"}) - assert_equal 'GET', request.method - assert_equal '/test?key=value', request.path - assert_matching_headers "oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"PLAINTEXT\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"5888bf0345e5d237%263196ffd991c8ebdb\", oauth_version=\"1.0\"", request['authorization'] + assert_equal "GET", request.method + assert_equal "/test?key=value", request.path + assert_matching_headers "oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"PLAINTEXT\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"5888bf0345e5d237%263196ffd991c8ebdb\", oauth_version=\"1.0\"", request["authorization"] end def test_that_using_auth_headers_on_post_requests_works @@ -42,52 +42,52 @@ def test_that_using_auth_headers_on_post_requests_works request.set_form_data( @request_parameters ) request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp}) - assert_equal 'POST', request.method - assert_equal '/test', request.path - assert_equal 'key=value', request.body + assert_equal "POST", request.method + assert_equal "/test", request.path + assert_equal "key=value", request.body correct_sorted_params = "oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"26g7wHTtNO6ZWJaLltcueppHYiI%3D\", oauth_version=\"1.0\"" - assert_matching_headers correct_sorted_params, request['authorization'] + assert_matching_headers correct_sorted_params, request["authorization"] end def test_that_using_auth_headers_on_post_requests_with_data_works request = Net::HTTP::Post.new(@request_uri.path) request.body = "data" - request.content_type = 'text/ascii' + request.content_type = "text/ascii" request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp}) - assert_equal 'POST', request.method - assert_equal '/test', request.path - assert_equal 'data', request.body - assert_equal 'text/ascii', request.content_type - assert_matching_headers "oauth_nonce=\"225579211881198842005988698334675835446\", oauth_body_hash=\"oXyaqmHoChv3HQ2FCvTluqmAC70%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"0DA6pGTapdHSqC15RZelY5rNLDw%3D\", oauth_version=\"1.0\"", request['authorization'] + assert_equal "POST", request.method + assert_equal "/test", request.path + assert_equal "data", request.body + assert_equal "text/ascii", request.content_type + assert_matching_headers "oauth_nonce=\"225579211881198842005988698334675835446\", oauth_body_hash=\"oXyaqmHoChv3HQ2FCvTluqmAC70%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"0DA6pGTapdHSqC15RZelY5rNLDw%3D\", oauth_version=\"1.0\"", request["authorization"] end def test_that_body_hash_is_obmitted_when_token_request request = Net::HTTP::Post.new(@request_uri.path) request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp, :token_request => true}) - assert_no_match(/oauth_body_hash/, request['authorization']) + assert_no_match(/oauth_body_hash/, request["authorization"]) end def test_that_body_hash_is_obmitted_when_no_algorithm_is_defined request = Net::HTTP::Post.new(@request_uri.path) request.body = "data" - request.content_type = 'text/ascii' - request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => 'plaintext'}) - - assert_equal 'POST', request.method - assert_equal '/test', request.path - assert_equal 'data', request.body - assert_equal 'text/ascii', request.content_type - assert_matching_headers "oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"plaintext\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"5888bf0345e5d237%263196ffd991c8ebdb\", oauth_version=\"1.0\"", request['authorization'] + request.content_type = "text/ascii" + request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => "plaintext"}) + + assert_equal "POST", request.method + assert_equal "/test", request.path + assert_equal "data", request.body + assert_equal "text/ascii", request.content_type + assert_matching_headers "oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"plaintext\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"5888bf0345e5d237%263196ffd991c8ebdb\", oauth_version=\"1.0\"", request["authorization"] end def test_that_version_is_added_to_existing_user_agent request = Net::HTTP::Post.new(@request_uri.path) - request['User-Agent'] = "MyApp" + request["User-Agent"] = "MyApp" request.set_form_data( @request_parameters ) request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp}) - assert_equal "MyApp (OAuth gem v#{OAuth::VERSION})", request['User-Agent'] + assert_equal "MyApp (OAuth gem v#{OAuth::VERSION})", request["User-Agent"] end def test_that_version_is_set_when_no_user_agent @@ -95,131 +95,131 @@ def test_that_version_is_set_when_no_user_agent request.set_form_data( @request_parameters ) request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp}) - assert_equal "OAuth gem v#{OAuth::VERSION}", request['User-Agent'] + assert_equal "OAuth gem v#{OAuth::VERSION}", request["User-Agent"] end def test_that_using_get_params_works request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s) - request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp}) + request.oauth!(@http, @consumer, @token, {:scheme => "query_string", :nonce => @nonce, :timestamp => @timestamp}) - assert_equal 'GET', request.method + assert_equal "GET", request.method uri = URI.parse(request.path) - assert_equal '/test', uri.path + assert_equal "/test", uri.path assert_nil uri.fragment assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=1oO2izFav1GP4kEH2EskwXkCRFg%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join("&") - assert_nil request['authorization'] + assert_nil request["authorization"] end def test_that_using_get_params_works_with_plaintext request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s) - request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'}) + request.oauth!(@http, @consumer, @token, {:scheme => "query_string", :nonce => @nonce, :timestamp => @timestamp, :signature_method => "PLAINTEXT"}) - assert_equal 'GET', request.method + assert_equal "GET", request.method uri = URI.parse(request.path) - assert_equal '/test', uri.path + assert_equal "/test", uri.path assert_nil uri.fragment assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=5888bf0345e5d237%263196ffd991c8ebdb&oauth_signature_method=PLAINTEXT&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join("&") - assert_nil request['authorization'] + assert_nil request["authorization"] end def test_that_using_post_params_works request = Net::HTTP::Post.new(@request_uri.path) request.set_form_data( @request_parameters ) - request.oauth!(@http, @consumer, @token, {:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp}) + request.oauth!(@http, @consumer, @token, {:scheme => "body", :nonce => @nonce, :timestamp => @timestamp}) - assert_equal 'POST', request.method - assert_equal '/test', request.path + assert_equal "POST", request.method + assert_equal "/test", request.path assert_match(/key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=26g7wHTtNO6ZWJaLltcueppHYiI%3[Dd]&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0/, request.body.split("&").sort.join("&")) - assert_nil request['authorization'] + assert_nil request["authorization"] end def test_that_using_post_params_works_with_plaintext request = Net::HTTP::Post.new(@request_uri.path) request.set_form_data( @request_parameters ) - request.oauth!(@http, @consumer, @token, {:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'}) + request.oauth!(@http, @consumer, @token, {:scheme => "body", :nonce => @nonce, :timestamp => @timestamp, :signature_method => "PLAINTEXT"}) - assert_equal 'POST', request.method - assert_equal '/test', request.path + assert_equal "POST", request.method + assert_equal "/test", request.path assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=5888bf0345e5d237%263196ffd991c8ebdb&oauth_signature_method=PLAINTEXT&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", request.body.split("&").sort.join("&") - assert_nil request['authorization'] + assert_nil request["authorization"] end def test_that_using_post_body_works request = Net::HTTP::Post.new(@request_uri.path) - request['content-type'] = 'application/x-www-form-urlencoded' - request.body = 'this is a test of the emergency broad cast system. This is only a test.' + request["content-type"] = "application/x-www-form-urlencoded" + request.body = "this is a test of the emergency broad cast system. This is only a test." request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp}) - assert_equal 'POST', request.method - assert_equal '/test', request.path - assert_match(/OAuth oauth_consumer_key="consumer_key_86cad9", oauth_nonce="225579211881198842005988698334675835446", oauth_signature="%2[fF]DMMBOJzQ6JmEaXlAXDLGtD1z2I%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1199645624", oauth_token="token_411a7f", oauth_version="1.0"/, request['authorization'].split("&").sort.join("&")) + assert_equal "POST", request.method + assert_equal "/test", request.path + assert_match(/OAuth oauth_consumer_key="consumer_key_86cad9", oauth_nonce="225579211881198842005988698334675835446", oauth_signature="%2[fF]DMMBOJzQ6JmEaXlAXDLGtD1z2I%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1199645624", oauth_token="token_411a7f", oauth_version="1.0"/, request["authorization"].split("&").sort.join("&")) # assert_nil request['authorization'] end def test_that_using_post_with_uri_params_works request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s) request.set_form_data( {} ) # just to make sure we have a correct mime type and thus no body hash - request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp}) + request.oauth!(@http, @consumer, @token, {:scheme => "query_string", :nonce => @nonce, :timestamp => @timestamp}) - assert_equal 'POST', request.method + assert_equal "POST", request.method uri = URI.parse(request.path) - assert_equal '/test', uri.path + assert_equal "/test", uri.path assert_nil uri.fragment - assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=26g7wHTtNO6ZWJaLltcueppHYiI%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join('&') + assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=26g7wHTtNO6ZWJaLltcueppHYiI%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join("&") assert_equal "", request.body - assert_nil request['authorization'] + assert_nil request["authorization"] end def test_that_using_post_with_uri_and_form_params_works request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s) - request.set_form_data( { 'key2' => 'value2' } ) + request.set_form_data( { "key2" => "value2" } ) request.oauth!(@http, @consumer, @token, {:scheme => :query_string, :nonce => @nonce, :timestamp => @timestamp}) - assert_equal 'POST', request.method + assert_equal "POST", request.method uri = URI.parse(request.path) - assert_equal '/test', uri.path + assert_equal "/test", uri.path assert_nil uri.fragment - assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=4kSU8Zd1blWo3W6qJH7eaRTMkg0%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join('&') + assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=4kSU8Zd1blWo3W6qJH7eaRTMkg0%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join("&") assert_equal "key2=value2", request.body - assert_nil request['authorization'] + assert_nil request["authorization"] end def test_that_using_post_with_uri_and_data_works request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s) request.body = "data" - request.content_type = 'text/ascii' + request.content_type = "text/ascii" request.oauth!(@http, @consumer, @token, {:scheme => :query_string, :nonce => @nonce, :timestamp => @timestamp}) - assert_equal 'POST', request.method + assert_equal "POST", request.method uri = URI.parse(request.path) - assert_equal '/test', uri.path + assert_equal "/test", uri.path assert_nil uri.fragment assert_equal "data", request.body - assert_equal 'text/ascii', request.content_type - assert_equal "key=value&oauth_body_hash=oXyaqmHoChv3HQ2FCvTluqmAC70%3D&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=MHRKU42iVHU4Ke9kBUDa9Zw6IAM%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join('&') - assert_nil request['authorization'] + assert_equal "text/ascii", request.content_type + assert_equal "key=value&oauth_body_hash=oXyaqmHoChv3HQ2FCvTluqmAC70%3D&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=MHRKU42iVHU4Ke9kBUDa9Zw6IAM%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join("&") + assert_nil request["authorization"] end def test_example_from_specs consumer=OAuth::Consumer.new("dpf43f3p2l4k3l03","kd94hf93k423kf44") - token = OAuth::Token.new('nnch734d00sl2jdk', 'pfkkdhi9sl3r4s00') - request_uri = URI.parse('http://photos.example.net/photos?file=vacation.jpg&size=original') - nonce = 'kllo9940pd9333jh' + token = OAuth::Token.new("nnch734d00sl2jdk", "pfkkdhi9sl3r4s00") + request_uri = URI.parse("http://photos.example.net/photos?file=vacation.jpg&size=original") + nonce = "kllo9940pd9333jh" timestamp = "1191242096" http = Net::HTTP.new(request_uri.host, request_uri.port) request = Net::HTTP::Get.new(request_uri.path + "?" + request_uri.query) signature_base_string=request.signature_base_string(http, consumer, token, {:nonce => nonce, :timestamp => timestamp}) - assert_equal 'GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal',signature_base_string + assert_equal "GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal",signature_base_string # request = Net::HTTP::Get.new(request_uri.path + "?" + request_uri.query) request.oauth!(http, consumer, token, {:nonce => nonce, :timestamp => timestamp, :realm=>"http://photos.example.net/"}) - assert_equal 'GET', request.method - correct_sorted_params = 'oauth_nonce="kllo9940pd9333jh", oauth_signature_method="HMAC-SHA1", oauth_token="nnch734d00sl2jdk", oauth_timestamp="1191242096", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_version="1.0"'.split(', ').sort + assert_equal "GET", request.method + correct_sorted_params = 'oauth_nonce="kllo9940pd9333jh", oauth_signature_method="HMAC-SHA1", oauth_token="nnch734d00sl2jdk", oauth_timestamp="1191242096", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_version="1.0"'.split(", ").sort correct_sorted_params.unshift 'OAuth realm="http://photos.example.net/"' - assert_equal correct_sorted_params, request['authorization'].split(', ').sort + assert_equal correct_sorted_params, request["authorization"].split(", ").sort end def test_step_by_step_token_request @@ -229,7 +229,7 @@ def test_step_by_step_token_request consumer=OAuth::Consumer.new( "key", "secret") - request_uri = URI.parse('http://term.ie/oauth/example/request_token.php') + request_uri = URI.parse("http://term.ie/oauth/example/request_token.php") nonce = rand(2**128).to_s timestamp = Time.now.to_i.to_s http = Net::HTTP.new(request_uri.host, request_uri.port) @@ -240,9 +240,9 @@ def test_step_by_step_token_request # request = Net::HTTP::Get.new(request_uri.path) request.oauth!(http, consumer, nil, {:scheme=>:query_string,:nonce => nonce, :timestamp => timestamp}) - assert_equal 'GET', request.method + assert_equal "GET", request.method assert_nil request.body - assert_nil request['authorization'] + assert_nil request["authorization"] # assert_equal 'OAuth oauth_nonce="kllo9940pd9333jh", oauth_signature_method="HMAC-SHA1", oauth_token="", oauth_timestamp="'+timestamp+'", oauth_consumer_key="key", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_version="1.0"', request['authorization'] response=http.request(request) @@ -261,14 +261,14 @@ def test_that_put_bodies_signed def test_that_put_bodies_not_signed_even_if_form_urlencoded request = Net::HTTP::Put.new(@request_uri.path) - request.set_form_data( { 'key2' => 'value2' } ) + request.set_form_data( { "key2" => "value2" } ) signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp }) assert_equal "PUT&http%3A%2F%2Fexample.com%2Ftest&key2%3Dvalue2%26oauth_consumer_key%3Dconsumer_key_86cad9%26oauth_nonce%3D225579211881198842005988698334675835446%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1199645624%26oauth_version%3D1.0", signature_base_string end def test_that_post_bodies_signed_if_form_urlencoded request = Net::HTTP::Post.new(@request_uri.path) - request.set_form_data( { 'key2' => 'value2' } ) + request.set_form_data( { "key2" => "value2" } ) signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp }) assert_equal "POST&http%3A%2F%2Fexample.com%2Ftest&key2%3Dvalue2%26oauth_consumer_key%3Dconsumer_key_86cad9%26oauth_nonce%3D225579211881198842005988698334675835446%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1199645624%26oauth_version%3D1.0", signature_base_string end @@ -282,7 +282,7 @@ def test_that_post_bodies_signed_if_other_content_type end def test_that_site_address_is_not_modified_in_place - options = { :site => 'http://twitter.com', :request_endpoint => 'http://api.twitter.com' } + options = { :site => "http://twitter.com", :request_endpoint => "http://api.twitter.com" } request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s) request.oauth!(@http, @consumer, @token, options) assert_equal "http://twitter.com", options[:site] diff --git a/test/units/test_net_http_request_proxy.rb b/test/units/test_net_http_request_proxy.rb index 76e07e17..2b487f42 100644 --- a/test/units/test_net_http_request_proxy.rb +++ b/test/units/test_net_http_request_proxy.rb @@ -1,72 +1,72 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) class NetHTTPRequestProxyTest < Minitest::Test def test_that_proxy_simple_get_request_works - request = Net::HTTP::Get.new('/test?key=value') - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value'}) + request = Net::HTTP::Get.new("/test?key=value") + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test?key=value"}) - expected_parameters = {'key' => ['value']} + expected_parameters = {"key" => ["value"]} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'GET', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "GET", request_proxy.method end def test_that_proxy_simple_post_request_works_with_arguments - request = Net::HTTP::Post.new('/test') - params = {'key' => 'value'} - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params}) + request = Net::HTTP::Post.new("/test") + params = {"key" => "value"} + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test", :parameters => params}) - expected_parameters = {'key' => ['value']} + expected_parameters = {"key" => ["value"]} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'POST', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "POST", request_proxy.method end def test_that_proxy_simple_post_request_works_with_form_data - request = Net::HTTP::Post.new('/test') - params = {'key' => 'value'} + request = Net::HTTP::Post.new("/test") + params = {"key" => "value"} request.set_form_data(params) - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'}) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test"}) - expected_parameters = {'key' => ['value']} + expected_parameters = {"key" => ["value"]} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'POST', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "POST", request_proxy.method end def test_that_proxy_simple_put_request_works_with_argugments - request = Net::HTTP::Put.new('/test') - params = {'key' => 'value'} - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params}) + request = Net::HTTP::Put.new("/test") + params = {"key" => "value"} + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test", :parameters => params}) - expected_parameters = {'key' => ['value']} + expected_parameters = {"key" => ["value"]} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'PUT', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "PUT", request_proxy.method end def test_that_proxy_simple_put_request_works_with_form_data - request = Net::HTTP::Put.new('/test') - params = {'key' => 'value'} + request = Net::HTTP::Put.new("/test") + params = {"key" => "value"} request.set_form_data(params) - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'}) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test"}) - expected_parameters = {'key' => ['value']} + expected_parameters = {"key" => ["value"]} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'PUT', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "PUT", request_proxy.method end def test_that_proxy_post_request_uses_post_parameters - request = Net::HTTP::Post.new('/test?key=value') - request.set_form_data({'key2' => 'value2'}) - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => {'key3' => 'value3'}}) + request = Net::HTTP::Post.new("/test?key=value") + request.set_form_data({"key2" => "value2"}) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test?key=value", :parameters => {"key3" => "value3"}}) - expected_parameters = {'key' => ['value'], 'key2' => ['value2'], 'key3' => ['value3']} + expected_parameters = {"key" => ["value"], "key2" => ["value2"], "key3" => ["value3"]} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'POST', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "POST", request_proxy.method end end diff --git a/test/units/test_oauth_helper.rb b/test/units/test_oauth_helper.rb index 0ad13424..5ddcbcc1 100644 --- a/test/units/test_oauth_helper.rb +++ b/test/units/test_oauth_helper.rb @@ -1,9 +1,9 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) class TestOAuthHelper < Minitest::Test def test_parse_valid_header - header = 'OAuth ' \ + header = "OAuth " \ 'realm="http://example.com/method", ' \ 'oauth_consumer_key="vince_clortho", ' \ 'oauth_token="token_value", ' \ @@ -14,14 +14,14 @@ def test_parse_valid_header params = OAuth::Helper.parse_header(header) - assert_equal "http://example.com/method", params['realm'] - assert_equal "vince_clortho", params['oauth_consumer_key'] - assert_equal "token_value", params['oauth_token'] - assert_equal "HMAC-SHA1", params['oauth_signature_method'] - assert_equal "signature_here", params['oauth_signature'] - assert_equal "1240004133", params['oauth_timestamp'] - assert_equal "nonce", params['oauth_nonce'] - assert_equal "1.0", params['oauth_version'] + assert_equal "http://example.com/method", params["realm"] + assert_equal "vince_clortho", params["oauth_consumer_key"] + assert_equal "token_value", params["oauth_token"] + assert_equal "HMAC-SHA1", params["oauth_signature_method"] + assert_equal "signature_here", params["oauth_signature"] + assert_equal "1240004133", params["oauth_timestamp"] + assert_equal "nonce", params["oauth_nonce"] + assert_equal "1.0", params["oauth_version"] end def test_parse_header_ill_formed @@ -33,7 +33,7 @@ def test_parse_header_ill_formed end def test_parse_header_contains_equals - header = 'OAuth ' \ + header = "OAuth " \ 'realm="http://example.com/method", ' \ 'oauth_consumer_key="vince_clortho", ' \ 'oauth_token="token_value", ' \ @@ -48,7 +48,7 @@ def test_parse_header_contains_equals end def test_parse_valid_header_with_and_signs - header = 'OAuth ' \ + header = "OAuth " \ 'realm="http://example.com/method"&' \ 'oauth_consumer_key="vince_clortho"&' \ 'oauth_token="token_value"&' \ @@ -59,36 +59,36 @@ def test_parse_valid_header_with_and_signs params = OAuth::Helper.parse_header(header) - assert_equal "http://example.com/method", params['realm'] - assert_equal "vince_clortho", params['oauth_consumer_key'] - assert_equal "token_value", params['oauth_token'] - assert_equal "HMAC-SHA1", params['oauth_signature_method'] - assert_equal "signature_here", params['oauth_signature'] - assert_equal "1240004133", params['oauth_timestamp'] - assert_equal "nonce", params['oauth_nonce'] - assert_equal "1.0", params['oauth_version'] + assert_equal "http://example.com/method", params["realm"] + assert_equal "vince_clortho", params["oauth_consumer_key"] + assert_equal "token_value", params["oauth_token"] + assert_equal "HMAC-SHA1", params["oauth_signature_method"] + assert_equal "signature_here", params["oauth_signature"] + assert_equal "1240004133", params["oauth_timestamp"] + assert_equal "nonce", params["oauth_nonce"] + assert_equal "1.0", params["oauth_version"] end def test_normalize params = { - 'oauth_nonce' => 'nonce', - 'weight' => { :value => "65" }, - 'oauth_signature_method' => 'HMAC-SHA1', - 'oauth_timestamp' => "1240004133", - 'oauth_consumer_key' => 'vince_clortho', - 'oauth_token' => 'token_value', - 'oauth_version' => "1.0" + "oauth_nonce" => "nonce", + "weight" => { :value => "65" }, + "oauth_signature_method" => "HMAC-SHA1", + "oauth_timestamp" => "1240004133", + "oauth_consumer_key" => "vince_clortho", + "oauth_token" => "token_value", + "oauth_version" => "1.0" } assert_equal("oauth_consumer_key=vince_clortho&oauth_nonce=nonce&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1240004133&oauth_token=token_value&oauth_version=1.0&weight%5Bvalue%5D=65", OAuth::Helper.normalize(params)) end def test_normalize_nested_query assert_equal([], OAuth::Helper.normalize_nested_query({})) - assert_equal(["foo=bar"], OAuth::Helper.normalize_nested_query({:foo => 'bar'})) - assert_equal(["prefix%5Bfoo%5D=bar"], OAuth::Helper.normalize_nested_query({:foo => 'bar'}, 'prefix')) + assert_equal(["foo=bar"], OAuth::Helper.normalize_nested_query({:foo => "bar"})) + assert_equal(["prefix%5Bfoo%5D=bar"], OAuth::Helper.normalize_nested_query({:foo => "bar"}, "prefix")) assert_equal(["prefix%5Buser%5D%5Bage%5D=12", "prefix%5Buser%5D%5Bdate%5D=2011-10-05", - "prefix%5Buser%5D%5Btwitter_id%5D=123"], OAuth::Helper.normalize_nested_query({:user => {:twitter_id => 123, :date => '2011-10-05', :age => 12}}, 'prefix')) + "prefix%5Buser%5D%5Btwitter_id%5D=123"], OAuth::Helper.normalize_nested_query({:user => {:twitter_id => 123, :date => "2011-10-05", :age => 12}}, "prefix")) end end diff --git a/test/units/test_rack_request_proxy.rb b/test/units/test_rack_request_proxy.rb index 99a3aa64..e348258d 100644 --- a/test/units/test_rack_request_proxy.rb +++ b/test/units/test_rack_request_proxy.rb @@ -1,39 +1,39 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) -require 'oauth/request_proxy/rack_request' +require "oauth/request_proxy/rack_request" class RackRequestProxyTest < Minitest::Test def test_that_proxy_simple_get_request_works - request = Rack::Request.new(Rack::MockRequest.env_for('http://example.com/test?key=value')) - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value'}) + request = Rack::Request.new(Rack::MockRequest.env_for("http://example.com/test?key=value")) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test?key=value"}) - expected_parameters = {'key' => 'value'} + expected_parameters = {"key" => "value"} assert_equal expected_parameters, request_proxy.parameters - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'GET', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "GET", request_proxy.method end def test_that_proxy_simple_post_request_works - request = Rack::Request.new(Rack::MockRequest.env_for('http://example.com/test', :method => 'POST')) - params = {'key' => 'value'} - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params}) + request = Rack::Request.new(Rack::MockRequest.env_for("http://example.com/test", :method => "POST")) + params = {"key" => "value"} + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test", :parameters => params}) - expected_parameters = {'key' => 'value'} + expected_parameters = {"key" => "value"} assert_equal expected_parameters, request_proxy.parameters - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'POST', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "POST", request_proxy.method end def test_that_proxy_post_and_get_request_works - request = Rack::Request.new(Rack::MockRequest.env_for('http://example.com/test?key=value', :method => 'POST', :input => 'key2=value2')) - params = {'key2' => 'value2'} - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => params}) + request = Rack::Request.new(Rack::MockRequest.env_for("http://example.com/test?key=value", :method => "POST", :input => "key2=value2")) + params = {"key2" => "value2"} + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test?key=value", :parameters => params}) - expected_parameters = {'key' => 'value', 'key2' => 'value2'} + expected_parameters = {"key" => "value", "key2" => "value2"} assert_equal expected_parameters, request_proxy.parameters - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'POST', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "POST", request_proxy.method end end diff --git a/test/units/test_request_token.rb b/test/units/test_request_token.rb index 850f28e4..f35ceccb 100644 --- a/test/units/test_request_token.rb +++ b/test/units/test_request_token.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) class StubbedToken < OAuth::RequestToken define_method :build_url_promoted do |root_domain, params| diff --git a/test/units/test_rest_client_request_proxy.rb b/test/units/test_rest_client_request_proxy.rb index 45115baa..bb737543 100644 --- a/test/units/test_rest_client_request_proxy.rb +++ b/test/units/test_rest_client_request_proxy.rb @@ -1,78 +1,78 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) begin - require 'oauth/request_proxy/rest_client_request' - require 'rest-client' + require "oauth/request_proxy/rest_client_request" + require "rest-client" class RestlClientRequestProxyTest < Minitest::Test def test_that_proxy_simple_get_request_works request = ::RestClient::Request.new(method: :get, url: "http://example.com/test?key=value") - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value'}) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test?key=value"}) - expected_parameters = {'key' => ['value']} + expected_parameters = {"key" => ["value"]} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'GET', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "GET", request_proxy.method end def test_that_proxy_simple_post_request_works_with_arguments request = ::RestClient::Request.new(method: :post, url: "http://example.com/test") - params = {'key' => 'value'} - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params}) + params = {"key" => "value"} + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test", :parameters => params}) - expected_parameters = {'key' => 'value'} + expected_parameters = {"key" => "value"} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'POST', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "POST", request_proxy.method end def test_that_proxy_simple_post_request_works_with_form_data request = ::RestClient::Request.new(method: :post, url: "http://example.com/test", - payload: {'key' => 'value'}, - headers: {'Content-Type' => 'application/x-www-form-urlencoded'}) - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'}) + payload: {"key" => "value"}, + headers: {"Content-Type" => "application/x-www-form-urlencoded"}) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test"}) - expected_parameters = {'key' => 'value'} + expected_parameters = {"key" => "value"} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'POST', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "POST", request_proxy.method end def test_that_proxy_simple_put_request_works_with_arguments request = ::RestClient::Request.new(method: :put, url: "http://example.com/test") - params = {'key' => 'value'} - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params}) + params = {"key" => "value"} + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test", :parameters => params}) - expected_parameters = {'key' => 'value'} + expected_parameters = {"key" => "value"} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'PUT', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "PUT", request_proxy.method end def test_that_proxy_simple_put_request_works_with_form_data request = ::RestClient::Request.new(method: :put, url: "http://example.com/test", - payload: {'key' => 'value'}, - headers: {'Content-Type' => 'application/x-www-form-urlencoded'}) - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'}) + payload: {"key" => "value"}, + headers: {"Content-Type" => "application/x-www-form-urlencoded"}) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test"}) - expected_parameters = {'key' => 'value'} + expected_parameters = {"key" => "value"} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'PUT', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "PUT", request_proxy.method end def test_that_proxy_post_request_works_with_mixed_parameter_sources - request = ::RestClient::Request.new(url: 'http://example.com/test?key=value', + request = ::RestClient::Request.new(url: "http://example.com/test?key=value", method: :post, - payload: {'key2' => 'value2'}, - headers: {'Content-Type' => 'application/x-www-form-urlencoded'}) - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => {'key3' => 'value3'}}) + payload: {"key2" => "value2"}, + headers: {"Content-Type" => "application/x-www-form-urlencoded"}) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test?key=value", :parameters => {"key3" => "value3"}}) - expected_parameters = {'key' => ['value'], 'key2' => 'value2', 'key3' => 'value3'} + expected_parameters = {"key" => ["value"], "key2" => "value2", "key3" => "value3"} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'POST', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "POST", request_proxy.method end end diff --git a/test/units/test_rsa_sha1.rb b/test/units/test_rsa_sha1.rb index dc4483d6..bba7c87e 100644 --- a/test/units/test_rsa_sha1.rb +++ b/test/units/test_rsa_sha1.rb @@ -1,7 +1,7 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) -require 'oauth/consumer' -require 'oauth/signature/rsa/sha1' +require "oauth/consumer" +require "oauth/signature/rsa/sha1" class TestSignatureRsaSha1 < Minitest::Test @@ -12,21 +12,21 @@ def setup end def test_that_rsa_sha1_implements_rsa_sha1 - assert OAuth::Signature.available_methods.include?('rsa-sha1') + assert OAuth::Signature.available_methods.include?("rsa-sha1") end def test_that_get_request_from_oauth_test_cases_produces_matching_signature_base_string sbs = OAuth::Signature.signature_base_string(@request, { :consumer => @consumer, - :uri => 'http://photos.example.net/photos' } ) + :uri => "http://photos.example.net/photos" } ) - assert_equal 'GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacaction.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3D13917289812797014437%26oauth_signature_method%3DRSA-SHA1%26oauth_timestamp%3D1196666512%26oauth_version%3D1.0%26size%3Doriginal', sbs + assert_equal "GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacaction.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3D13917289812797014437%26oauth_signature_method%3DRSA-SHA1%26oauth_timestamp%3D1196666512%26oauth_version%3D1.0%26size%3Doriginal", sbs end def test_that_get_request_from_oauth_test_cases_produces_matching_signature signature = OAuth::Signature.sign(@request, { :consumer => @consumer, - :uri => 'http://photos.example.net/photos' } ) + :uri => "http://photos.example.net/photos" } ) - assert_equal 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=', signature + assert_equal "jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=", signature end def test_that_get_request_from_oauth_test_cases_produces_matching_signature_using_private_key_file @@ -34,9 +34,9 @@ def test_that_get_request_from_oauth_test_cases_produces_matching_signature_usin signature = OAuth::Signature.sign(@request, { :consumer => @consumer, :private_key_file=>pem_path, - :uri => 'http://photos.example.net/photos' } ) + :uri => "http://photos.example.net/photos" } ) - assert_equal 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=', signature + assert_equal "jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=", signature end def test_that_get_request_from_oauth_test_cases_verifies_signature @@ -44,20 +44,20 @@ def test_that_get_request_from_oauth_test_cases_verifies_signature @consumer = OAuth::Consumer.new(consumer_key, x509_certificate) assert OAuth::Signature.verify(@request, { :consumer => @consumer, - :uri => 'http://photos.example.net/photos' } ) + :uri => "http://photos.example.net/photos" } ) end def test_that_get_request_from_oauth_test_cases_verifies_signature_with_pem @request = Net::HTTP::Get.new("/photos?oauth_signature_method=RSA-SHA1&oauth_version=1.0&oauth_consumer_key=#{consumer_key}&oauth_timestamp=1196666512&oauth_nonce=13917289812797014437&file=vacaction.jpg&size=original&oauth_signature=jvTp%2FwX1TYtByB1m%2BPbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2%2F9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW%2F%2Fe%2BRinhejgCuzoH26dyF8iY2ZZ%2F5D1ilgeijhV%2FvBka5twt399mXwaYdCwFYE%3D") assert OAuth::Signature.verify(@request, { :consumer => @consumer, - :uri => 'http://photos.example.net/photos' } ) + :uri => "http://photos.example.net/photos" } ) end private def consumer_key - 'dpf43f3p2l4k3l03' + "dpf43f3p2l4k3l03" end def x509_certificate diff --git a/test/units/test_server.rb b/test/units/test_server.rb index 7af2816a..57ca43dc 100644 --- a/test/units/test_server.rb +++ b/test/units/test_server.rb @@ -1,6 +1,6 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) -require 'oauth/server' +require "oauth/server" class ServerTest < Minitest::Test def setup diff --git a/test/units/test_signature.rb b/test/units/test_signature.rb index c1a32357..0fa87d48 100644 --- a/test/units/test_signature.rb +++ b/test/units/test_signature.rb @@ -1,14 +1,14 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) class TestOauth < Minitest::Test def test_parameter_escaping_kcode_invariant %w(n N e E s S u U).each do |kcode| - assert_equal '%E3%81%82', OAuth::Helper.escape('あ'), + assert_equal "%E3%81%82", OAuth::Helper.escape("あ"), "Failed to correctly escape Japanese under $KCODE = #{kcode}" - assert_equal '%C3%A9', OAuth::Helper.escape('é'), + assert_equal "%C3%A9", OAuth::Helper.escape("é"), "Failed to correctly escape e+acute under $KCODE = #{kcode}" end end diff --git a/test/units/test_signature_base.rb b/test/units/test_signature_base.rb index cbfb732d..a77506e1 100644 --- a/test/units/test_signature_base.rb +++ b/test/units/test_signature_base.rb @@ -1,7 +1,7 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) -require 'oauth/signature/base' -require 'net/http' +require "oauth/signature/base" +require "net/http" class SignatureBaseTest < Minitest::Test @@ -22,7 +22,7 @@ def test_that_initialize_requires_a_valid_request_argument def test_that_initialize_succeeds_when_the_request_proxy_is_valid # this isn't quite valid, but it will do. - raw_request = Net::HTTP::Get.new('/test') + raw_request = Net::HTTP::Get.new("/test") request = OAuth::RequestProxy.proxy(raw_request) OAuth::Signature::Base.new(request) { |token| diff --git a/test/units/test_signature_hmac_sha1.rb b/test/units/test_signature_hmac_sha1.rb index a9c37667..fa37bd96 100644 --- a/test/units/test_signature_hmac_sha1.rb +++ b/test/units/test_signature_hmac_sha1.rb @@ -1,41 +1,41 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) -require 'oauth/signature/hmac/sha1' +require "oauth/signature/hmac/sha1" class SignatureHMACSHA1Test < Minitest::Test def test_that_verify_returns_true_when_the_request_signature_is_right request = OAuth::RequestProxy::MockRequest.new( - 'method' => 'POST', - 'uri' => 'https://photos.example.net/initialize', - 'parameters' => { - 'oauth_consumer_key' => 'dpf43f3p2l4k3l03', - 'oauth_signature_method' => 'HMAC-SHA1', - 'oauth_timestamp' => '137131200', - 'oauth_nonce' => 'wIjqoS', - 'oauth_callback' => 'http://printer.example.com/ready', - 'oauth_version' => '1.0', - 'oauth_signature' => 'xcHYBV3AbyoDz7L4dV10P3oLCjY=' + "method" => "POST", + "uri" => "https://photos.example.net/initialize", + "parameters" => { + "oauth_consumer_key" => "dpf43f3p2l4k3l03", + "oauth_signature_method" => "HMAC-SHA1", + "oauth_timestamp" => "137131200", + "oauth_nonce" => "wIjqoS", + "oauth_callback" => "http://printer.example.com/ready", + "oauth_version" => "1.0", + "oauth_signature" => "xcHYBV3AbyoDz7L4dV10P3oLCjY=" } ) - assert OAuth::Signature::HMAC::SHA1.new(request, :consumer_secret => 'kd94hf93k423kf44').verify + assert OAuth::Signature::HMAC::SHA1.new(request, :consumer_secret => "kd94hf93k423kf44").verify end def test_that_verify_returns_false_when_the_request_signature_is_wrong # Test a bug in the OAuth::Signature::Base#== method: when the Base64.decode64 method is # used on the "self" and "other" signature (as in version 0.4.7), the result may be incorrectly "true". request = OAuth::RequestProxy::MockRequest.new( - 'method' => 'POST', - 'uri' => 'https://photos.example.net/initialize', - 'parameters' => { - 'oauth_consumer_key' => 'dpf43f3p2l4k3l03', - 'oauth_signature_method' => 'HMAC-SHA1', - 'oauth_timestamp' => '137131200', - 'oauth_nonce' => 'wIjqoS', - 'oauth_callback' => 'http://printer.example.com/ready', - 'oauth_version' => '1.0', - 'oauth_signature' => 'xcHYBV3AbyoDz7L4dV10P3oLCjZ=' + "method" => "POST", + "uri" => "https://photos.example.net/initialize", + "parameters" => { + "oauth_consumer_key" => "dpf43f3p2l4k3l03", + "oauth_signature_method" => "HMAC-SHA1", + "oauth_timestamp" => "137131200", + "oauth_nonce" => "wIjqoS", + "oauth_callback" => "http://printer.example.com/ready", + "oauth_version" => "1.0", + "oauth_signature" => "xcHYBV3AbyoDz7L4dV10P3oLCjZ=" } ) - assert !OAuth::Signature::HMAC::SHA1.new(request, :consumer_secret => 'kd94hf93k423kf44').verify + assert !OAuth::Signature::HMAC::SHA1.new(request, :consumer_secret => "kd94hf93k423kf44").verify end end diff --git a/test/units/test_signature_hmac_sha256.rb b/test/units/test_signature_hmac_sha256.rb index 0cfc59a4..2e923ba2 100644 --- a/test/units/test_signature_hmac_sha256.rb +++ b/test/units/test_signature_hmac_sha256.rb @@ -1,41 +1,41 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) -require 'oauth/signature/hmac/sha256' +require "oauth/signature/hmac/sha256" class SignatureHMACSHA256Test < Minitest::Test def test_that_verify_returns_true_when_the_request_signature_is_right request = OAuth::RequestProxy::MockRequest.new( - 'method' => 'POST', - 'uri' => 'https://photos.example.net/initialize', - 'parameters' => { - 'oauth_consumer_key' => 'dpf43f3p2l4k3l03', - 'oauth_signature_method' => 'HMAC-SHA256', - 'oauth_timestamp' => '137131200', - 'oauth_nonce' => 'wIjqoS', - 'oauth_callback' => 'http://printer.example.com/ready', - 'oauth_version' => '1.0', - 'oauth_signature' => 'tkpCGNHi3laWBHQ9+Ka5IOeixEuhxg12LTMlLJxQxKc=' + "method" => "POST", + "uri" => "https://photos.example.net/initialize", + "parameters" => { + "oauth_consumer_key" => "dpf43f3p2l4k3l03", + "oauth_signature_method" => "HMAC-SHA256", + "oauth_timestamp" => "137131200", + "oauth_nonce" => "wIjqoS", + "oauth_callback" => "http://printer.example.com/ready", + "oauth_version" => "1.0", + "oauth_signature" => "tkpCGNHi3laWBHQ9+Ka5IOeixEuhxg12LTMlLJxQxKc=" } ) - assert OAuth::Signature::HMAC::SHA256.new(request, :consumer_secret => 'kd94hf93k423kf44').verify + assert OAuth::Signature::HMAC::SHA256.new(request, :consumer_secret => "kd94hf93k423kf44").verify end def test_that_verify_returns_false_when_the_request_signature_is_wrong # Test a bug in the OAuth::Signature::Base#== method: when the Base64.decode64 method is # used on the "self" and "other" signature (as in version 0.4.7), the result may be incorrectly "true". request = OAuth::RequestProxy::MockRequest.new( - 'method' => 'POST', - 'uri' => 'https://photos.example.net/initialize', - 'parameters' => { - 'oauth_consumer_key' => 'dpf43f3p2l4k3l03', - 'oauth_signature_method' => 'HMAC-SHA256', - 'oauth_timestamp' => '137131200', - 'oauth_nonce' => 'wIjqoS', - 'oauth_callback' => 'http://printer.example.com/ready', - 'oauth_version' => '1.0', - 'oauth_signature' => 'tkpCGNHi3laWBHQ9+Ka5IOeixEuhxg12LTMlLJxQxKZ=' + "method" => "POST", + "uri" => "https://photos.example.net/initialize", + "parameters" => { + "oauth_consumer_key" => "dpf43f3p2l4k3l03", + "oauth_signature_method" => "HMAC-SHA256", + "oauth_timestamp" => "137131200", + "oauth_nonce" => "wIjqoS", + "oauth_callback" => "http://printer.example.com/ready", + "oauth_version" => "1.0", + "oauth_signature" => "tkpCGNHi3laWBHQ9+Ka5IOeixEuhxg12LTMlLJxQxKZ=" } ) - assert !OAuth::Signature::HMAC::SHA256.new(request, :consumer_secret => 'kd94hf93k423kf44').verify + assert !OAuth::Signature::HMAC::SHA256.new(request, :consumer_secret => "kd94hf93k423kf44").verify end end diff --git a/test/units/test_signature_plain_text.rb b/test/units/test_signature_plain_text.rb index 37db8535..ac145108 100644 --- a/test/units/test_signature_plain_text.rb +++ b/test/units/test_signature_plain_text.rb @@ -1,32 +1,32 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) -require 'oauth/signature/plaintext' +require "oauth/signature/plaintext" class TestSignaturePlaintext < Minitest::Test def test_that_plaintext_implements_plaintext - assert OAuth::Signature.available_methods.include?('plaintext') + assert OAuth::Signature.available_methods.include?("plaintext") end def test_that_get_request_from_oauth_test_cases_produces_matching_signature - request = Net::HTTP::Get.new('/photos?file=vacation.jpg&size=original&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk&oauth_signature=kd94hf93k423kf44%26&oauth_timestamp=1191242096&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=PLAINTEXT') + request = Net::HTTP::Get.new("/photos?file=vacation.jpg&size=original&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk&oauth_signature=kd94hf93k423kf44%26&oauth_timestamp=1191242096&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=PLAINTEXT") - consumer = OAuth::Consumer.new('dpf43f3p2l4k3l03','kd94hf93k423kf44') - token = OAuth::Token.new('nnch734d00sl2jdk', nil) + consumer = OAuth::Consumer.new("dpf43f3p2l4k3l03","kd94hf93k423kf44") + token = OAuth::Token.new("nnch734d00sl2jdk", nil) assert OAuth::Signature.verify(request, { :consumer => consumer, :token => token, - :uri => 'http://photos.example.net/photos' } ) + :uri => "http://photos.example.net/photos" } ) end def test_that_get_request_from_oauth_test_cases_produces_matching_signature_part_two - request = Net::HTTP::Get.new('/photos?file=vacation.jpg&size=original&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk&oauth_signature=kd94hf93k423kf44%26pfkkdhi9sl3r4s00&oauth_timestamp=1191242096&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=PLAINTEXT') + request = Net::HTTP::Get.new("/photos?file=vacation.jpg&size=original&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk&oauth_signature=kd94hf93k423kf44%26pfkkdhi9sl3r4s00&oauth_timestamp=1191242096&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=PLAINTEXT") - consumer = OAuth::Consumer.new('dpf43f3p2l4k3l03','kd94hf93k423kf44') - token = OAuth::Token.new('nnch734d00sl2jdk', 'pfkkdhi9sl3r4s00') + consumer = OAuth::Consumer.new("dpf43f3p2l4k3l03","kd94hf93k423kf44") + token = OAuth::Token.new("nnch734d00sl2jdk", "pfkkdhi9sl3r4s00") assert OAuth::Signature.verify(request, { :consumer => consumer, :token => token, - :uri => 'http://photos.example.net/photos' } ) + :uri => "http://photos.example.net/photos" } ) end end diff --git a/test/units/test_token.rb b/test/units/test_token.rb index d373f779..43b6da35 100644 --- a/test/units/test_token.rb +++ b/test/units/test_token.rb @@ -1,6 +1,6 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) -require 'oauth/token' +require "oauth/token" class TestToken < Minitest::Test @@ -8,8 +8,8 @@ def setup end def test_token_constructor_produces_valid_token - token = OAuth::Token.new('xyz', '123') - assert_equal 'xyz', token.token - assert_equal '123', token.secret + token = OAuth::Token.new("xyz", "123") + assert_equal "xyz", token.token + assert_equal "123", token.secret end end diff --git a/test/units/test_typhoeus_request_proxy.rb b/test/units/test_typhoeus_request_proxy.rb index 3cf4ae31..5b20166e 100644 --- a/test/units/test_typhoeus_request_proxy.rb +++ b/test/units/test_typhoeus_request_proxy.rb @@ -1,98 +1,98 @@ -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path("../../test_helper", __FILE__) begin -require 'oauth/request_proxy/typhoeus_request' -require 'typhoeus' +require "oauth/request_proxy/typhoeus_request" +require "typhoeus" class TyphoeusRequestProxyTest < Minitest::Test def test_that_proxy_simple_get_request_works - request = ::Typhoeus::Request.new('/test?key=value') - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value'}) + request = ::Typhoeus::Request.new("/test?key=value") + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test?key=value"}) - expected_parameters = {'key' => ['value']} + expected_parameters = {"key" => ["value"]} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'GET', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "GET", request_proxy.method end def test_that_proxy_simple_post_request_works_with_arguments - request = Typhoeus::Request.new('/test', :method => :post) - params = {'key' => 'value'} - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params}) + request = Typhoeus::Request.new("/test", :method => :post) + params = {"key" => "value"} + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test", :parameters => params}) - expected_parameters = {'key' => 'value'} + expected_parameters = {"key" => "value"} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'POST', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "POST", request_proxy.method end def test_that_proxy_simple_post_request_works_with_form_data - request = Typhoeus::Request.new('/test', :method => :post, - :params => {'key' => 'value'}, - :headers => {'Content-Type' => 'application/x-www-form-urlencoded'}) - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'}) + request = Typhoeus::Request.new("/test", :method => :post, + :params => {"key" => "value"}, + :headers => {"Content-Type" => "application/x-www-form-urlencoded"}) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test"}) - expected_parameters = {'key' => ['value']} + expected_parameters = {"key" => ["value"]} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'POST', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "POST", request_proxy.method end def test_that_proxy_simple_put_request_works_with_arguments - request = Typhoeus::Request.new('/test', :method => :put) - params = {'key' => 'value'} - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params}) + request = Typhoeus::Request.new("/test", :method => :put) + params = {"key" => "value"} + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test", :parameters => params}) - expected_parameters = {'key' => 'value'} + expected_parameters = {"key" => "value"} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'PUT', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "PUT", request_proxy.method end def test_that_proxy_simple_put_request_works_with_form_data - request = Typhoeus::Request.new('/test', :method => :put, :params => {'key' => 'value'}) - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'}) + request = Typhoeus::Request.new("/test", :method => :put, :params => {"key" => "value"}) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test"}) - expected_parameters = {'key' => ['value']} + expected_parameters = {"key" => ["value"]} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'PUT', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "PUT", request_proxy.method end def test_that_proxy_simple_patch_request_works_with_arguments - request = Typhoeus::Request.new('/test', :method => :patch) - params = {'key' => 'value'} - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params}) + request = Typhoeus::Request.new("/test", :method => :patch) + params = {"key" => "value"} + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test", :parameters => params}) - expected_parameters = {'key' => 'value'} + expected_parameters = {"key" => "value"} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'PATCH', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "PATCH", request_proxy.method end def test_that_proxy_simple_patch_request_works_with_form_data - request = Typhoeus::Request.new('/test', :method => :patch, :params => {'key' => 'value'}) - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'}) + request = Typhoeus::Request.new("/test", :method => :patch, :params => {"key" => "value"}) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test"}) - expected_parameters = {'key' => ['value']} + expected_parameters = {"key" => ["value"]} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'PATCH', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "PATCH", request_proxy.method end def test_that_proxy_post_request_works_with_mixed_parameter_sources - request = Typhoeus::Request.new('/test?key=value', + request = Typhoeus::Request.new("/test?key=value", :method => :post, - :params => {'key2' => 'value2'}, - :headers => {'Content-Type' => 'application/x-www-form-urlencoded'}) - request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => {'key3' => 'value3'}}) + :params => {"key2" => "value2"}, + :headers => {"Content-Type" => "application/x-www-form-urlencoded"}) + request_proxy = OAuth::RequestProxy.proxy(request, {:uri => "http://example.com/test?key=value", :parameters => {"key3" => "value3"}}) - expected_parameters = {'key' => ['value'], 'key2' => ['value2'], 'key3' => 'value3'} + expected_parameters = {"key" => ["value"], "key2" => ["value2"], "key3" => "value3"} assert_equal expected_parameters, request_proxy.parameters_for_signature - assert_equal 'http://example.com/test', request_proxy.normalized_uri - assert_equal 'POST', request_proxy.method + assert_equal "http://example.com/test", request_proxy.normalized_uri + assert_equal "POST", request_proxy.method end end From 9d5f13f53fc9bc1bd6e05347b4358a54ed08cd3a Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Mon, 1 Nov 2021 00:34:58 +0700 Subject: [PATCH 02/12] =?UTF-8?q?=F0=9F=92=9A=20Constrain=20linting=20and?= =?UTF-8?q?=20coverage=20to=20Ruby=202.6+?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Boling --- oauth.gemspec | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/oauth.gemspec b/oauth.gemspec index adcd4793..af0d51a7 100644 --- a/oauth.gemspec +++ b/oauth.gemspec @@ -30,8 +30,12 @@ Gem::Specification.new do |spec| # This gem will work with 2.0 or greater... spec.required_ruby_version = ">= 2.0" + ruby_version = Gem::Version.new(RUBY_VERSION) + linting = ruby_version >= Gem::Version.new('2.6') && RUBY_ENGINE == 'ruby' + coverage = linting + # Nokogiri 1.7 does not accept Ruby 2.0 - spec.add_development_dependency("nokogiri", "~> 1.6.8") if RUBY_VERSION < "2.1" + spec.add_development_dependency("nokogiri", "~> 1.6.8") if ruby_version < Gem::Version.new('2.0') spec.add_development_dependency("actionpack", ">= 5.0") spec.add_development_dependency("byebug", "~> 11.1") @@ -44,16 +48,20 @@ Gem::Specification.new do |spec| spec.add_development_dependency("rack-test") spec.add_development_dependency("rake", "~> 13.0") spec.add_development_dependency("rest-client") - spec.add_development_dependency("rubocop", "~> 1.22") - spec.add_development_dependency("rubocop-faker", "~> 1.1") - spec.add_development_dependency("rubocop-md", "~> 1.0") - spec.add_development_dependency("rubocop-minitest", "~> 0.15") - spec.add_development_dependency("rubocop-packaging", "~> 0.5") - spec.add_development_dependency("rubocop-performance", "~> 1.11") - spec.add_development_dependency("rubocop-rake", "~> 0.6") - spec.add_development_dependency("rubocop-thread_safety", "~> 0.4") - spec.add_development_dependency("simplecov", "~> 0.21") - spec.add_development_dependency("simplecov-cobertura", "~> 1.4") + if linting + spec.add_development_dependency("rubocop", "~> 1.22") + spec.add_development_dependency("rubocop-faker", "~> 1.1") + spec.add_development_dependency("rubocop-md", "~> 1.0") + spec.add_development_dependency("rubocop-minitest", "~> 0.15") + spec.add_development_dependency("rubocop-packaging", "~> 0.5") + spec.add_development_dependency("rubocop-performance", "~> 1.11") + spec.add_development_dependency("rubocop-rake", "~> 0.6") + spec.add_development_dependency("rubocop-thread_safety", "~> 0.4") + end + if coverage + spec.add_development_dependency("simplecov", "~> 0.21") + spec.add_development_dependency("simplecov-cobertura", "~> 1.4") + end spec.add_development_dependency("typhoeus", ">= 0.1.13") spec.add_development_dependency("webmock", "< 2.0") end From 3ebb1b1876ccdd661a4073421d64618f88dafd8b Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Mon, 1 Nov 2021 00:38:42 +0700 Subject: [PATCH 03/12] =?UTF-8?q?=F0=9F=91=B7=20Allow=20rake=20to=20run=20?= =?UTF-8?q?when=20Rubocop=20not=20loaded?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Boling --- Rakefile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index 9323eb28..071cccc9 100644 --- a/Rakefile +++ b/Rakefile @@ -11,8 +11,13 @@ Rake::TestTask.new do |t| t.verbose = true end -require "rubocop/rake_task" - -RuboCop::RakeTask.new +begin + require "rubocop/rake_task" + RuboCop::RakeTask.new +rescue LoadError + task :rubocop do + warn "RuboCop is disabled on Ruby #{RUBY_VERSION}" + end +end task default: %i[test rubocop] From aab523c839b8abd9958d0fb456be4e5d75f45c07 Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Mon, 1 Nov 2021 00:40:57 +0700 Subject: [PATCH 04/12] =?UTF-8?q?=F0=9F=9A=A8=20Lint=20Drubbing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Boling --- oauth.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oauth.gemspec b/oauth.gemspec index af0d51a7..9ab69a44 100644 --- a/oauth.gemspec +++ b/oauth.gemspec @@ -31,11 +31,11 @@ Gem::Specification.new do |spec| spec.required_ruby_version = ">= 2.0" ruby_version = Gem::Version.new(RUBY_VERSION) - linting = ruby_version >= Gem::Version.new('2.6') && RUBY_ENGINE == 'ruby' + linting = ruby_version >= Gem::Version.new("2.6") && RUBY_ENGINE == "ruby" coverage = linting # Nokogiri 1.7 does not accept Ruby 2.0 - spec.add_development_dependency("nokogiri", "~> 1.6.8") if ruby_version < Gem::Version.new('2.0') + spec.add_development_dependency("nokogiri", "~> 1.6.8") if ruby_version < Gem::Version.new("2.0") spec.add_development_dependency("actionpack", ">= 5.0") spec.add_development_dependency("byebug", "~> 11.1") From f29bfd8fe74bf1198f79a13ece1ec77ffa6259fa Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Mon, 1 Nov 2021 00:43:11 +0700 Subject: [PATCH 05/12] =?UTF-8?q?=F0=9F=92=9A=20Only=20run=20coverage=20in?= =?UTF-8?q?=20Ruby=202.6+?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Boling --- test/test_helper.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 19e6cb9c..a236518f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,10 +2,14 @@ ENV["RACK_ENV"] = "test" +ruby_version = Gem::Version.new(RUBY_VERSION) # Code coverage -require "simplecov" -require "simplecov-cobertura" -SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter unless ENV["HTML_COVERAGE"] == "true" +coverage = ruby_version >= Gem::Version.new("2.6") && RUBY_ENGINE == "ruby" +if coverage + require "simplecov" + require "simplecov-cobertura" + SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter unless ENV["HTML_COVERAGE"] == "true" +end # require third-party code From 5a60f72c85e36ce44700e9c9d116f6c19fc8af14 Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Mon, 1 Nov 2021 00:45:19 +0700 Subject: [PATCH 06/12] =?UTF-8?q?=F0=9F=91=B7=20Ignore=20test=20directory?= =?UTF-8?q?=20when=20computing=20coverage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Boling --- .simplecov | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.simplecov b/.simplecov index 94a1c1e8..882da010 100644 --- a/.simplecov +++ b/.simplecov @@ -1,5 +1,5 @@ # frozen_string_literal: true SimpleCov.start do - add_filter "/spec/" + add_filter "/test/" end From 5282bceee15a71f5d2cf406c48f1475ee1423d8a Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Mon, 1 Nov 2021 00:49:09 +0700 Subject: [PATCH 07/12] =?UTF-8?q?=F0=9F=94=A8=20Make=20executable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Boling --- examples/twitter.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 examples/twitter.rb diff --git a/examples/twitter.rb b/examples/twitter.rb old mode 100644 new mode 100755 From 783e29456934528421bf95fa2a12cec7d790c74b Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Mon, 1 Nov 2021 00:56:46 +0700 Subject: [PATCH 08/12] =?UTF-8?q?=F0=9F=92=9A=20Carefully=20load=20conditi?= =?UTF-8?q?onal=20libraries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Boling --- oauth.gemspec | 8 +++++--- test/test_helper.rb | 9 +++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/oauth.gemspec b/oauth.gemspec index 9ab69a44..a37aa0df 100644 --- a/oauth.gemspec +++ b/oauth.gemspec @@ -31,14 +31,16 @@ Gem::Specification.new do |spec| spec.required_ruby_version = ">= 2.0" ruby_version = Gem::Version.new(RUBY_VERSION) - linting = ruby_version >= Gem::Version.new("2.6") && RUBY_ENGINE == "ruby" - coverage = linting + minimum_version = ->(version) { ruby_version >= Gem::Version.new(version) && RUBY_ENGINE == "ruby" } + linting = minimum_version.call("2.6") + coverage = minimum_version.call("2.6") + debug = minimum_version.call("2.4") # Nokogiri 1.7 does not accept Ruby 2.0 spec.add_development_dependency("nokogiri", "~> 1.6.8") if ruby_version < Gem::Version.new("2.0") spec.add_development_dependency("actionpack", ">= 5.0") - spec.add_development_dependency("byebug", "~> 11.1") + spec.add_development_dependency("byebug", "~> 11.1") if debug spec.add_development_dependency("curb") spec.add_development_dependency("em-http-request", "~> 1.1.7") spec.add_development_dependency("iconv") diff --git a/test/test_helper.rb b/test/test_helper.rb index a236518f..d2328521 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,8 +3,10 @@ ENV["RACK_ENV"] = "test" ruby_version = Gem::Version.new(RUBY_VERSION) -# Code coverage -coverage = ruby_version >= Gem::Version.new("2.6") && RUBY_ENGINE == "ruby" +minimum_version = ->(version) { ruby_version >= Gem::Version.new(version) && RUBY_ENGINE == "ruby" } +coverage = minimum_version.call("2.6") +debug = minimum_version.call("2.4") + if coverage require "simplecov" require "simplecov-cobertura" @@ -12,8 +14,7 @@ end # require third-party code - -require "byebug" +require "byebug" if debug require "stringio" require "minitest/autorun" require "mocha/mini_test" From ed17179b084d2bb6301c7f8ad2a3223184630c60 Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Mon, 1 Nov 2021 00:57:22 +0700 Subject: [PATCH 09/12] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20No=20reason=20to?= =?UTF-8?q?=20modify=20$LOAD=5FPATH?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Boling --- test/test_helper.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index d2328521..4595b8b1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -22,8 +22,6 @@ require "webmock/minitest" # require our lib - -$LOAD_PATH << File.dirname(__FILE__) + "/../lib/" require "oauth" # require our support code From e4dd2cdd8b976c5d932d829139be63ce7792da7e Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Mon, 1 Nov 2021 00:59:20 +0700 Subject: [PATCH 10/12] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20Will=20Ruby=202.2?= =?UTF-8?q?=20build=20on=20Ubuntu=2018.04=20in=202021=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Boling --- .github/workflows/unsupported.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unsupported.yml b/.github/workflows/unsupported.yml index c0e8a95b..5025c968 100644 --- a/.github/workflows/unsupported.yml +++ b/.github/workflows/unsupported.yml @@ -23,6 +23,7 @@ jobs: - 2.5 - 2.4 - 2.3 + - 2.2 runs-on: ubuntu-18.04 continue-on-error: ${{ matrix.allow_failure || endsWith(matrix.ruby, 'head') }} steps: From 551cf8460af8d25f9318faac0f4bbc62e64128ef Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Mon, 1 Nov 2021 01:04:31 +0700 Subject: [PATCH 11/12] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20Only=20upload=20c?= =?UTF-8?q?overage=20on=20oldest=20supported=20Ruby=20(i.e.=202.6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Boling --- .github/workflows/supported.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/supported.yml b/.github/workflows/supported.yml index 8aef9282..871ede52 100644 --- a/.github/workflows/supported.yml +++ b/.github/workflows/supported.yml @@ -49,6 +49,7 @@ jobs: - name: Run tests run: bundle exec rake test - uses: codecov/codecov-action@v2 + if: matrix.ruby == '2.6' && github.event_name != 'pull_request' with: flags: unittests name: codecov-upload From 90fbb9bb251d1ba89bb4360fc2c312ffabc1e2de Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Mon, 1 Nov 2021 01:07:38 +0700 Subject: [PATCH 12/12] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20Revert=20to=20Cod?= =?UTF-8?q?eClimate=20defaults=20(and=20UI=20config)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Boling --- .codeclimate.yml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 .codeclimate.yml diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index 93032191..00000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -engines: - duplication: - enabled: true - config: - languages: - - ruby - fixme: - enabled: true - rubocop: - enabled: true -ratings: - paths: - - "**.rb" -exclude_paths: -- test/