From a4437ed7eb75172c1ff145398bd27f0af6af3027 Mon Sep 17 00:00:00 2001 From: Peter Boling Date: 2022年8月30日 07:22:19 +0700 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=93=9D=20Document=20migration=20to=20?= =?UTF-8?q?Gitlab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 379 +----------------------------------------------------- 1 file changed, 6 insertions(+), 373 deletions(-) diff --git a/README.md b/README.md index d9cb7037..f6d006ef 100644 --- a/README.md +++ b/README.md @@ -7,385 +7,18 @@

-# Ruby OAuth +# Ruby OAuth has moved to GitLab -OAuth 1.0 is an industry-standard protocol for authorization. - -This is a RubyGem for implementing both OAuth 1.0 clients and servers in Ruby applications. -See the sibling `oauth2` gem for OAuth 2.0 implementations in Ruby. - -* [OAuth 1.0 Spec][oauth1-spec] -* [oauth2 sibling gem][sibling-gem] for OAuth 2.0 implementations in Ruby. - -[oauth1-spec]: http://oauth.net/core/1.0/ -[sibling-gem]: https://github.com/oauth-xx/oauth-ruby - -**New EOL Policy** - -Versions 1.x will be EOL no later than April, 2025. -Versions 0.6.x will be EOL no later than April, 2024. -Versions 0.5.x will be EOL no later than April, 2023. - -This will facilitate dropping support for old, dead, and crusty versions of Ruby. - -Non-commercial support for the oldest version of Ruby (which itself is going EOL) will be dropped each year in April. - -Please upgrade to version 1.1. The only breaking change in 1.x is dropping old Rubies. - -## Status - - - -| | Project | bundle add oauth | -|:----|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| 1️⃣ | name, license, docs | [![RubyGems.org][⛳️name-img]][⛳️gem] [![License: MIT][🖇src-license-img]][🖇src-license] [![RubyDoc.info][🚎yard-img]][🚎yard] | -| 2️⃣ | version & activity | [![Gem Version][⛳️version-img]][⛳️gem] [![Total Downloads][🖇DL-total-img]][⛳️gem] [![Download Rank][🏘DL-rank-img]][⛳️gem] [![Source Code][🚎src-home-img]][🚎src-home] [![Open PRs][🖐prs-o-img]][🖐prs-o] [![Closed PRs][🧮prs-c-img]][🧮prs-c] | -| 3️⃣ | maintenance & linting | [![Maintainability][⛳cclim-maint-img♻️]][⛳cclim-maint] [![Helpers][🖇triage-help-img]][🖇triage-help] [![Depfu][🏘depfu-img♻️]][🏘depfu♻️] [![Contributors][🚎contributors-img]][🚎contributors] [![Style][🖐style-wf-img]][🖐style-wf] [![Kloc Roll][🧮kloc-img]][🧮kloc] | -| 4️⃣ | testing | [![Open Issues][⛳iss-o-img]][⛳iss-o] [![Closed Issues][🖇iss-c-img]][🖇iss-c] [![Supported][🏘sup-wf-img]][🏘sup-wf] [![Heads][🚎heads-wf-img]][🚎heads-wf] [![MacOS][🧮mac-wf-img]][🧮mac-wf] [![Windows][📗win-wf-img]][📗win-wf] | -| 5️⃣ | coverage & security | [![CodeClimate][⛳cclim-cov-img♻️]][⛳cclim-cov] [![CodeCov][🖇codecov-img♻️]][🖇codecov] [![Coveralls][🏘coveralls-img]][🏘coveralls] [![Security Policy][🚎sec-pol-img]][🚎sec-pol] [![CodeQL][🖐codeQL-img]][🖐codeQL] [![Code Coverage][🧮cov-wf-img]][🧮cov-wf] | -| 6️⃣ | resources | [![Discussion][⛳gh-discussions-img]][⛳gh-discussions] [![Get help on Codementor][🖇codementor-img]][🖇codementor] [![Chat][🏘chat-img]][🏘chat] [![Blog][🚎blog-img]][🚎blog] [![Blog][🖐wiki-img]][🖐wiki] | -| 7️⃣ | spread 💖 | [![Liberapay Patrons][⛳liberapay-img]][⛳liberapay] [![Sponsor Me][🖇sponsor-img]][🖇sponsor] [![Tweet @ Peter][🏘tweet-img]][🏘tweet] [🌏][aboutme] [👼][angelme] [💻][coderme] | - - - - -[⛳️gem]: https://rubygems.org/gems/oauth -[⛳️name-img]: https://img.shields.io/badge/name-oauth-brightgreen.svg?style=flat -[🖇src-license]: https://opensource.org/licenses/MIT -[🖇src-license-img]: https://img.shields.io/badge/License-MIT-green.svg -[🚎yard]: https://www.rubydoc.info/github/oauth-xx/oauth-ruby -[🚎yard-img]: https://img.shields.io/badge/documentation-rubydoc-brightgreen.svg?style=flat - - -[⛳️version-img]: http://img.shields.io/gem/v/oauth.svg -[🖇DL-total-img]: https://img.shields.io/gem/dt/oauth.svg -[🏘DL-rank-img]: https://img.shields.io/gem/rt/oauth.svg -[🚎src-home]: https://github.com/oauth-xx/oauth-ruby -[🚎src-home-img]: https://img.shields.io/badge/source-github-brightgreen.svg?style=flat -[🖐prs-o]: https://github.com/oauth-xx/oauth-ruby/pulls -[🖐prs-o-img]: https://img.shields.io/github/issues-pr/oauth-xx/oauth-ruby -[🧮prs-c]: https://github.com/oauth-xx/oauth-ruby/pulls?q=is%3Apr+is%3Aclosed -[🧮prs-c-img]: https://img.shields.io/github/issues-pr-closed/oauth-xx/oauth-ruby -[📗next]: https://github.com/oauth-xx/oauth-ruby/milestone/1 -[📗next-img]: https://img.shields.io/github/milestones/progress/oauth-xx/oauth-ruby/1?label=Next%20Version - - -[⛳cclim-maint]: https://codeclimate.com/github/oauth-xx/oauth-ruby/maintainability -[⛳cclim-maint-img♻️]: https://api.codeclimate.com/v1/badges/3cf23270c21e8791d788/maintainability -[🖇triage-help]: https://www.codetriage.com/oauth-xx/oauth-ruby -[🖇triage-help-img]: https://www.codetriage.com/oauth-xx/oauth-ruby/badges/users.svg -[🏘depfu♻️]: https://depfu.com/github/oauth-xx/oauth-ruby?project_id=22868 -[🏘depfu-img♻️]: https://badges.depfu.com/badges/d570491bac0ad3b0b65deb3c82028327/count.svg -[🚎contributors]: https://github.com/oauth-xx/oauth-ruby/graphs/contributors -[🚎contributors-img]: https://img.shields.io/github/contributors-anon/oauth-xx/oauth-ruby -[🖐style-wf]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/style.yml -[🖐style-wf-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/style.yml/badge.svg -[🧮kloc]: https://www.youtube.com/watch?v=dQw4w9WgXcQ -[🧮kloc-img]: https://img.shields.io/tokei/lines/github.com/oauth-xx/oauth-ruby - - -[⛳iss-o]: https://github.com/oauth-xx/oauth-ruby/issues -[⛳iss-o-img]: https://img.shields.io/github/issues-raw/oauth-xx/oauth-ruby -[🖇iss-c]: https://github.com/oauth-xx/oauth-ruby/issues?q=is%3Aissue+is%3Aclosed -[🖇iss-c-img]: https://img.shields.io/github/issues-closed-raw/oauth-xx/oauth-ruby -[🏘sup-wf]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/supported.yml -[🏘sup-wf-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/supported.yml/badge.svg -[🚎heads-wf]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/heads.yml -[🚎heads-wf-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/heads.yml/badge.svg -[🧮mac-wf]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/macos.yml -[🧮mac-wf-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/macos.yml/badge.svg -[📗win-wf]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/windows.yml -[📗win-wf-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/windows.yml/badge.svg - - -[⛳cclim-cov]: https://codeclimate.com/github/oauth-xx/oauth-ruby/test_coverage -[⛳cclim-cov-img♻️]: https://api.codeclimate.com/v1/badges/3cf23270c21e8791d788/test_coverage -[🖇codecov-img♻️]: https://codecov.io/gh/oauth-xx/oauth-ruby/branch/main/graph/badge.svg?token=4ZNAWNxrf9 -[🖇codecov]: https://codecov.io/gh/oauth-xx/oauth-ruby -[🏘coveralls]: https://coveralls.io/github/oauth-xx/oauth-ruby?branch=main -[🏘coveralls-img]: https://coveralls.io/repos/github/oauth-xx/oauth-ruby/badge.svg?branch=main -[🚎sec-pol]: https://github.com/oauth-xx/oauth-ruby/blob/main/SECURITY.md -[🚎sec-pol-img]: https://img.shields.io/badge/security-policy-brightgreen.svg?style=flat -[🖐codeQL]: https://github.com/oauth-xx/oauth-ruby/security/code-scanning -[🖐codeQL-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/codeql-analysis.yml/badge.svg -[🧮cov-wf]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/coverage.yml -[🧮cov-wf-img]: https://github.com/oauth-xx/oauth-ruby/actions/workflows/coverage.yml/badge.svg - - -[⛳gh-discussions]: https://github.com/oauth-xx/oauth-ruby/discussions -[⛳gh-discussions-img]: https://img.shields.io/github/discussions/oauth-xx/oauth-ruby -[🖇codementor]: https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github -[🖇codementor-img]: https://cdn.codementor.io/badges/get_help_github.svg -[🏘chat]: https://gitter.im/oauth-xx/oauth-ruby -[🏘chat-img]: https://img.shields.io/gitter/room/oauth-xx/oauth-ruby.svg -[🚎blog]: http://www.railsbling.com/tags/oauth-ruby/ -[🚎blog-img]: https://img.shields.io/badge/blog-railsbling-brightgreen.svg?style=flat -[🖐wiki]: https://github.com/oauth-xx/oauth-ruby/wiki -[🖐wiki-img]: https://img.shields.io/badge/wiki-examples-brightgreen.svg?style=flat - - -[⛳liberapay-img]: https://img.shields.io/liberapay/patrons/pboling.svg?logo=liberapay -[⛳liberapay]: https://liberapay.com/pboling/donate -[🖇sponsor-img]: https://img.shields.io/badge/sponsor-pboling.svg?style=social&logo=github -[🖇sponsor]: https://github.com/sponsors/pboling -[🏘tweet-img]: https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow -[🏘tweet]: http://twitter.com/galtzo - - -[railsbling]: http://www.railsbling.com -[peterboling]: http://www.peterboling.com - -## Installation - -Install the gem and add to the application's Gemfile by executing: - - $ bundle add oauth - -If bundler is not being used to manage dependencies, install the gem by executing: - - $ gem install oauth - -## OAuth for Enterprise - -Available as part of the Tidelift Subscription. - -The maintainers of OAuth2 and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. [Learn more.](https://tidelift.com/subscription/pkg/rubygems-oauth?utm_source=rubygems-oauth&utm_medium=referral&utm_campaign=enterprise) - -## Security contact information [![Security Policy][🚎sec-pol-img]][🚎sec-pol] - -To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). -Tidelift will coordinate the fix and disclosure. - -For more see [SECURITY.md][🚎sec-pol]. - -## Compatibility - -Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.7, 3.0, and -3.1. Ruby is limited to 2.7+ in the gemspec, and this will change with minor version bumps, -while the gem is still in 0.x, in accordance with the SemVer spec. - -The `main` branch now targets 1.1.x releases, for Ruby>= 2.7. -See `v1.0-maintenance` (EOL April, 2025) branch for Ruby>= 2.7. -See `v0.6-maintenance` (EOL April, 2024) branch for Ruby>= 2.4. -See `v0.5-maintenance` (EOL April, 2023) branch for Ruby>= 2.0. - -NOTE: No further releases of version < 1.0.x are anticipated. - -
- Ruby Engine Compatibility Policy - -This gem is tested against MRI, and to a lesser extent, against JRuby, and Truffleruby. -Each of those has varying versions that target a specific version of MRI Ruby. -This gem should work in the just-listed Ruby engines according to the targeted MRI compatibility in the table below. -If you would like to add support for additional engines, -first make sure Github Actions supports the engine, -then submit a PR to the correct maintenance branch as according to the table below. -
- -
- Ruby Version Compatibility Policy - -If something doesn't work on one of these interpreters, it's a bug. - -This library may inadvertently work (or seem to work) on other Ruby -implementations, however support will only be provided for the versions listed -above. - -If you would like this library to support another Ruby version, you may -volunteer to be a maintainer. Being a maintainer entails making sure all tests -run and pass on that implementation. When something breaks on your -implementation, you will be responsible for providing patches in a timely -fashion. If critical issues for a particular implementation exist at the time -of a major release, support for that Ruby version may be dropped. -
- -| | Ruby OAuth Version | Maintenance Branch | EOL | 🚂 Compatibility | Official 💎 | Unofficial 💎 | Incidental 💎 | -|:----|--------------------|--------------------|-----------|------------------------|----------------------|------------------------------|---------------| -| 1️⃣ | 1.0.x | `main` | | Rails 6, 7 | 2.7, 3.0, 3.1 | sorry, not sorry | nope | -| 2️⃣ | 0.6.x | `v0.6-maintenance` | 04/2024 | Rails 5, 6, 7 | 2.7, 3.0, 3.1 | 2.5, 2.6 | 2.4 | -| 3️⃣ | 0.5.x | `v0.5-maintenance` | 04/2023 | Rails 2, 3, 4, 5, 6, 7 | 2.7, 3.0, 3.1 | 2.1, 2.2, 2.3, 2.4, 2.5, 2.6 | 2.0 | -| 4️⃣ | older | N/A | yesterday | | Best of luck to you! | Please upgrade! | noop | - -NOTE: Once 1.0 is released, the 0.x series will only receive critical bug and security updates. -See [SECURITY.md][🚎sec-pol] - -🚂 NOTE: See notes on Rails in next section. - -## Basics - -This is a ruby library which is intended to be used in creating Ruby Consumer -and Service Provider applications. It is NOT a Rails plugin, but could easily -be used for the foundation for such a Rails plugin. - -This gem was originally extracted from @pelle's [oauth-plugin](https://github.com/pelle/oauth-plugin) -gem. After extraction that gem was made to depend on this gem. - -Unfortunately, this gem does have some Rails related bits that are -**optional** to load. You don't need Rails! The Rails bits may be pulled out -into a separate gem with the 1.x minor updates of this gem. - -## Extensions - -* [oauth-tty (on Gitlab)](https://gitlab.com/oauth-xx/oauth-tty) ([rubygems.org](https://rubygems.org/gems/oauth-tty)) - -## Usage - -We need to specify the `oauth_callback` url explicitly, otherwise it defaults to -"oob" (Out of Band) - -```ruby -callback_url = "http://127.0.0.1:3000/oauth/callback" -``` - -Create a new `OAuth::Consumer` instance by passing it a configuration hash: - -```ruby -oauth_consumer = OAuth::Consumer.new("key", "secret", site: "https://agree2") -``` - -Start the process by requesting a token - -```ruby -request_token = oauth_consumer.get_request_token(oauth_callback: callback_url) - -session[:token] = request_token.token -session[:token_secret] = request_token.secret -redirect_to request_token.authorize_url(oauth_callback: callback_url) -``` - -When user returns create an access_token - -```ruby -hash = { oauth_token: session[:token], oauth_token_secret: session[:token_secret] } -request_token = OAuth::RequestToken.from_hash(oauth_consumer, hash) -access_token = request_token.get_access_token -# For 3-legged authorization, flow oauth_verifier is passed as param in callback -# access_token = request_token.get_access_token(oauth_verifier: params[:oauth_verifier]) -@photos = access_token.get("/photos.xml") -``` - -Now that you have an access token, you can use Typhoeus to interact with the -OAuth provider if you choose. - -```ruby -require "typhoeus" -require "oauth/request_proxy/typhoeus_request" -oauth_params = { consumer: oauth_consumer, token: access_token } -hydra = Typhoeus::Hydra.new -req = Typhoeus::Request.new(uri, options) # :method needs to be specified in options -oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(request_uri: uri)) -req.options[:headers]["Authorization"] = oauth_helper.header # Signs the request -hydra.queue(req) -hydra.run -@response = req.response -``` - -## More Information +Please update references: https://gitlab.com/oauth-xx/oauth/ +* Source Code: [![Gitlab](https://img.shields.io/badge/source-gitlab-brightgreen.svg?style=flat)][source] * RubyDoc Documentation: [![RubyDoc.info](https://img.shields.io/badge/documentation-rubydoc-brightgreen.svg?style=flat)][documentation] * Mailing List/Google Group: [![Mailing List](https://img.shields.io/badge/group-mailinglist-violet.svg?style=social&logo=google)][mailinglist] -* GitHub Discussions: [![Discussion](https://img.shields.io/badge/discussions-github-brightgreen.svg?style=flat)][gh_discussions] * Live Chat on Gitter: [![Join the chat at https://gitter.im/oauth-xx/oauth-ruby](https://badges.gitter.im/Join%20Chat.svg)][chat] * Maintainer's Blog: [![Blog](https://img.shields.io/badge/blog-railsbling-brightgreen.svg?style=flat)][blogpage] -## Contributing - -See [CONTRIBUTING.md][contributing] - -## Contributors - -[![Contributors](https://contrib.rocks/image?repo=oauth-xx/oauth-ruby)][contributors] - -Made with [contributors-img][contrib-rocks]. - -[contrib-rocks]: https://contrib.rocks - -## Versioning - -This library aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations of this scheme should be reported as -bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be -immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new -major versions. Compatibility with a major and minor versions of Ruby will only be changed with a major version bump. - -As a result of this policy, you can (and should) specify a dependency on this gem using -the [Pessimistic Version Constraint][pvc] with two digits of precision. - -For example: - -```ruby -spec.add_dependency "oauth", "~> 1.1" -``` - -## License - -The gem is available as open source under the terms of -the [MIT License][license] [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)][license-ref]. -See [LICENSE][license] for the [Copyright Notice][copyright-notice-explainer]. - -## Contact - -OAuth Ruby has been created and maintained by a large number of talented -individuals. The current maintainer is Peter Boling ([@pboling][gh_sponsors]). - -Comments are welcome. Contact the [OAuth Ruby mailing list (Google Group)][mailinglist] or [GitHub Discussions][gh_discussions]. - -[comment]: (Following links are used by README, CONTRIBUTING, Homepage) - -[conduct]: https://github.com/oauth-xx/oauth-ruby/blob/main/CODE_OF_CONDUCT.md -[contributing]: https://github.com/oauth-xx/oauth-ruby/blob/main/CONTRIBUTING.md -[contributors]: https://github.com/oauth-xx/oauth-ruby/graphs/contributors +[documentation]: https://rubydoc.info/github/oauth-xx/oauth-ruby [mailinglist]: http://groups.google.com/group/oauth-ruby -[source]: https://github.com/oauth-xx/oauth-ruby/ - -[comment]: (Following links are used by README, Homepage) - -[aboutme]: https://about.me/peter.boling -[actions]: https://github.com/oauth-xx/oauth-ruby/actions -[angelme]: https://angel.co/peter-boling -[blogpage]: http://www.railsbling.com/tags/oauth/ [chat]: https://gitter.im/oauth-xx/oauth-ruby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge -[climate_coverage]: https://codeclimate.com/github/oauth-xx/oauth-ruby/test_coverage -[climate_maintainability]: https://codeclimate.com/github/oauth-xx/oauth-ruby/maintainability -[code_triage]: https://www.codetriage.com/oauth-xx/oauth-ruby -[codecov_coverage]: https://codecov.io/gh/oauth-xx/oauth-ruby -[coderme]:http://coderwall.com/pboling -[depfu]: https://depfu.com/github/oauth-xx/oauth-ruby?project_id=22868 -[documentation]: https://rubydoc.info/github/oauth-xx/oauth-ruby -[followme-img]: https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow -[gh_discussions]: https://github.com/oauth-xx/oauth-ruby/discussions -[gh_sponsors]: https://github.com/sponsors/pboling -[license]: https://github.com/oauth-xx/oauth-ruby/blob/main/LICENSE -[license-ref]: https://opensource.org/licenses/MIT -[liberapay_donate]: https://liberapay.com/pboling/donate -[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint -[rubygems]: https://rubygems.org/gems/oauth -[security]: https://github.com/oauth-xx/oauth-ruby/blob/main/SECURITY.md -[semver]: http://semver.org/ -[tweetme]: http://twitter.com/galtzo +[blogpage]: http://www.railsbling.com/tags/oauth/ +[source]: https://gitlab.com/oauth-xx/oauth/ From fe08f86818553dbcbb581fd0c1609061509a20d4 Mon Sep 17 00:00:00 2001 From: Peter Boling Date: 2022年8月30日 18:36:26 +0700 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9D=20Document=20how=20to=20update?= =?UTF-8?q?=20local?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index f6d006ef..e9667502 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,11 @@ Please update references: https://gitlab.com/oauth-xx/oauth/ +If you have the project checked out, simply: +```bash +git remote set-url origin git@gitlab.com:oauth-xx/oauth.git +``` + * Source Code: [![Gitlab](https://img.shields.io/badge/source-gitlab-brightgreen.svg?style=flat)][source] * RubyDoc Documentation: [![RubyDoc.info](https://img.shields.io/badge/documentation-rubydoc-brightgreen.svg?style=flat)][documentation] * Mailing List/Google Group: [![Mailing List](https://img.shields.io/badge/group-mailinglist-violet.svg?style=social&logo=google)][mailinglist] From ea451ae36c30476dedfb68154be629ca1580884a Mon Sep 17 00:00:00 2001 From: Peter Boling Date: 2022年9月19日 09:58:19 +0700 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=8E=89=20Migration=20from=20Github=20?= =?UTF-8?q?to=20Gitlab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/dependabot.yml | 10 - .github/workflows/codeql-analysis.yml | 70 -- .github/workflows/coverage.yml | 123 --- .github/workflows/heads.yml | 62 -- .github/workflows/macos.yml | 59 -- .github/workflows/style.yml | 50 - .github/workflows/supported.yml | 70 -- .github/workflows/windows.yml | 58 -- .gitignore | 8 - .overcommit.yml | 31 - .rubocop.yml | 44 - .rubocop_todo.yml | 114 --- .simplecov | 33 - Gemfile | 39 - LICENSE => LICENSE.txt | 0 Rakefile | 23 - TODO | 32 - bin/bundle | 118 --- bin/rake | 27 - bin/rubocop | 27 - docs/images/logo/Oauth_logo.svg | 61 -- docs/images/logo/README.txt | 17 - docs/images/logo/ruby-logo-198px.svg | 948 ------------------ examples/twitter.rb | 44 - examples/yql.rb | 45 - gemfiles/README.md | 32 - gemfiles/a6.gemfile | 9 - gemfiles/a7.gemfile | 9 - lib/oauth.rb | 20 - lib/oauth/client.rb | 6 - lib/oauth/client/action_controller_request.rb | 67 -- lib/oauth/client/em_http.rb | 119 --- lib/oauth/client/helper.rb | 102 -- lib/oauth/client/net_http.rb | 128 --- lib/oauth/consumer.rb | 463 --------- lib/oauth/errors.rb | 5 - lib/oauth/errors/error.rb | 6 - lib/oauth/errors/problem.rb | 17 - lib/oauth/errors/unauthorized.rb | 18 - lib/oauth/helper.rb | 121 --- lib/oauth/oauth.rb | 15 - lib/oauth/oauth_test_helper.rb | 27 - lib/oauth/request_proxy.rb | 27 - .../action_controller_request.rb | 68 -- .../request_proxy/action_dispatch_request.rb | 11 - lib/oauth/request_proxy/base.rb | 182 ---- lib/oauth/request_proxy/curb_request.rb | 61 -- lib/oauth/request_proxy/em_http_request.rb | 76 -- lib/oauth/request_proxy/jabber_request.rb | 44 - lib/oauth/request_proxy/mock_request.rb | 46 - lib/oauth/request_proxy/net_http.rb | 80 -- lib/oauth/request_proxy/rack_request.rb | 48 - .../request_proxy/rest_client_request.rb | 66 -- lib/oauth/request_proxy/typhoeus_request.rb | 60 -- lib/oauth/server.rb | 68 -- lib/oauth/signature.rb | 48 - lib/oauth/signature/base.rb | 103 -- lib/oauth/signature/hmac/sha1.rb | 23 - lib/oauth/signature/hmac/sha256.rb | 23 - lib/oauth/signature/plaintext.rb | 27 - lib/oauth/signature/rsa/sha1.rb | 58 -- lib/oauth/token.rb | 9 - lib/oauth/tokens/access_token.rb | 85 -- lib/oauth/tokens/consumer_token.rb | 35 - lib/oauth/tokens/request_token.rb | 46 - lib/oauth/tokens/server_token.rb | 10 - lib/oauth/tokens/token.rb | 19 - lib/oauth/version.rb | 7 - oauth.gemspec | 74 -- .../1_0-final/construct_request_url_test.rb | 60 -- .../normalize_request_parameters_test.rb | 86 -- .../1_0-final/parameter_encodings_test.rb | 89 -- .../1_0-final/signature_base_strings_test.rb | 77 -- test/keys/rsa.cert | 11 - test/keys/rsa.pem | 16 - test/support/minitest_helpers.rb | 29 - test/support/oauth_case.rb | 21 - test/test_helper.rb | 62 -- test/units/access_token_test.rb | 28 - .../action_controller_request_proxy_test.rb | 146 --- .../action_dispatch_request_proxy_test.rb | 41 - test/units/cli_test.rb | 307 ------ test/units/client_helper_test.rb | 149 --- test/units/consumer_integration_test.rb | 322 ------ test/units/consumer_test.rb | 365 ------- test/units/curb_request_proxy_test.rb | 77 -- test/units/em_http_client_test.rb | 77 -- test/units/em_http_request_proxy_test.rb | 118 --- test/units/hmac_sha1_test.rb | 22 - test/units/hmac_sha256_test.rb | 23 - test/units/net_http_client_test.rb | 340 ------- test/units/net_http_request_proxy_test.rb | 74 -- test/units/oauth_helper_test.rb | 112 --- test/units/rack_request_proxy_test.rb | 41 - test/units/request_token_test.rb | 82 -- test/units/rest_client_request_proxy_test.rb | 90 -- test/units/rsa_sha1_test.rb | 81 -- test/units/server_test.rb | 43 - test/units/signature_base_test.rb | 33 - test/units/signature_hmac_sha1_test.rb | 43 - test/units/signature_hmac_sha256_test.rb | 43 - test/units/signature_plain_text_test.rb | 31 - test/units/signature_test.rb | 14 - test/units/token_test.rb | 15 - test/units/typhoeus_request_proxy_test.rb | 102 -- 105 files changed, 7951 deletions(-) delete mode 100644 .github/dependabot.yml delete mode 100644 .github/workflows/codeql-analysis.yml delete mode 100644 .github/workflows/coverage.yml delete mode 100644 .github/workflows/heads.yml delete mode 100644 .github/workflows/macos.yml delete mode 100644 .github/workflows/style.yml delete mode 100644 .github/workflows/supported.yml delete mode 100644 .github/workflows/windows.yml delete mode 100644 .gitignore delete mode 100644 .overcommit.yml delete mode 100644 .rubocop.yml delete mode 100644 .rubocop_todo.yml delete mode 100644 .simplecov delete mode 100644 Gemfile rename LICENSE => LICENSE.txt (100%) delete mode 100644 Rakefile delete mode 100644 TODO delete mode 100755 bin/bundle delete mode 100755 bin/rake delete mode 100755 bin/rubocop delete mode 100644 docs/images/logo/Oauth_logo.svg delete mode 100644 docs/images/logo/README.txt delete mode 100644 docs/images/logo/ruby-logo-198px.svg delete mode 100755 examples/twitter.rb delete mode 100755 examples/yql.rb delete mode 100644 gemfiles/README.md delete mode 100644 gemfiles/a6.gemfile delete mode 100644 gemfiles/a7.gemfile delete mode 100644 lib/oauth.rb delete mode 100644 lib/oauth/client.rb delete mode 100644 lib/oauth/client/action_controller_request.rb delete mode 100644 lib/oauth/client/em_http.rb delete mode 100644 lib/oauth/client/helper.rb delete mode 100644 lib/oauth/client/net_http.rb delete mode 100644 lib/oauth/consumer.rb delete mode 100644 lib/oauth/errors.rb delete mode 100644 lib/oauth/errors/error.rb delete mode 100644 lib/oauth/errors/problem.rb delete mode 100644 lib/oauth/errors/unauthorized.rb delete mode 100644 lib/oauth/helper.rb delete mode 100644 lib/oauth/oauth.rb delete mode 100644 lib/oauth/oauth_test_helper.rb delete mode 100644 lib/oauth/request_proxy.rb delete mode 100644 lib/oauth/request_proxy/action_controller_request.rb delete mode 100644 lib/oauth/request_proxy/action_dispatch_request.rb delete mode 100644 lib/oauth/request_proxy/base.rb delete mode 100644 lib/oauth/request_proxy/curb_request.rb delete mode 100644 lib/oauth/request_proxy/em_http_request.rb delete mode 100644 lib/oauth/request_proxy/jabber_request.rb delete mode 100644 lib/oauth/request_proxy/mock_request.rb delete mode 100644 lib/oauth/request_proxy/net_http.rb delete mode 100644 lib/oauth/request_proxy/rack_request.rb delete mode 100644 lib/oauth/request_proxy/rest_client_request.rb delete mode 100644 lib/oauth/request_proxy/typhoeus_request.rb delete mode 100644 lib/oauth/server.rb delete mode 100644 lib/oauth/signature.rb delete mode 100644 lib/oauth/signature/base.rb delete mode 100644 lib/oauth/signature/hmac/sha1.rb delete mode 100644 lib/oauth/signature/hmac/sha256.rb delete mode 100644 lib/oauth/signature/plaintext.rb delete mode 100644 lib/oauth/signature/rsa/sha1.rb delete mode 100644 lib/oauth/token.rb delete mode 100644 lib/oauth/tokens/access_token.rb delete mode 100644 lib/oauth/tokens/consumer_token.rb delete mode 100644 lib/oauth/tokens/request_token.rb delete mode 100644 lib/oauth/tokens/server_token.rb delete mode 100644 lib/oauth/tokens/token.rb delete mode 100644 lib/oauth/version.rb delete mode 100644 oauth.gemspec delete mode 100644 test/cases/spec/1_0-final/construct_request_url_test.rb delete mode 100644 test/cases/spec/1_0-final/normalize_request_parameters_test.rb delete mode 100644 test/cases/spec/1_0-final/parameter_encodings_test.rb delete mode 100644 test/cases/spec/1_0-final/signature_base_strings_test.rb delete mode 100644 test/keys/rsa.cert delete mode 100644 test/keys/rsa.pem delete mode 100644 test/support/minitest_helpers.rb delete mode 100644 test/support/oauth_case.rb delete mode 100644 test/test_helper.rb delete mode 100644 test/units/access_token_test.rb delete mode 100644 test/units/action_controller_request_proxy_test.rb delete mode 100644 test/units/action_dispatch_request_proxy_test.rb delete mode 100644 test/units/cli_test.rb delete mode 100644 test/units/client_helper_test.rb delete mode 100644 test/units/consumer_integration_test.rb delete mode 100644 test/units/consumer_test.rb delete mode 100644 test/units/curb_request_proxy_test.rb delete mode 100644 test/units/em_http_client_test.rb delete mode 100644 test/units/em_http_request_proxy_test.rb delete mode 100644 test/units/hmac_sha1_test.rb delete mode 100644 test/units/hmac_sha256_test.rb delete mode 100644 test/units/net_http_client_test.rb delete mode 100644 test/units/net_http_request_proxy_test.rb delete mode 100644 test/units/oauth_helper_test.rb delete mode 100644 test/units/rack_request_proxy_test.rb delete mode 100644 test/units/request_token_test.rb delete mode 100644 test/units/rest_client_request_proxy_test.rb delete mode 100644 test/units/rsa_sha1_test.rb delete mode 100644 test/units/server_test.rb delete mode 100644 test/units/signature_base_test.rb delete mode 100644 test/units/signature_hmac_sha1_test.rb delete mode 100644 test/units/signature_hmac_sha256_test.rb delete mode 100644 test/units/signature_plain_text_test.rb delete mode 100644 test/units/signature_test.rb delete mode 100644 test/units/token_test.rb delete mode 100644 test/units/typhoeus_request_proxy_test.rb diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index c3240fb6..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: 2 -updates: - - package-ecosystem: bundler - directory: "/" - schedule: - interval: daily - time: "04:30" - open-pull-requests-limit: 10 - ignore: - - dependency-name: "rubocop-lts" diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index d3f85059..00000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,70 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ main, "*-maintenance" ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ main, "*-maintenance" ] - schedule: - - cron: '35 1 * * 5' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'ruby' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] - # Learn more about CodeQL language support at https://git.io/codeql-language-support - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - # i️ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index e2bb595d..00000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,123 +0,0 @@ -name: Code Coverage - -env: - CI_CODECOV: true - COVER_ALL: true - -on: - push: - branches: - - 'main' - - '*-maintenance' - - '*-dev' - - '*-stable' - tags: - - '!*' # Do not execute on tags - pull_request: - branches: - - '*' - # Allow manually triggering the workflow. - workflow_dispatch: - -# Cancels all previous workflow runs for the same branch that have not yet completed. -concurrency: - # The concurrency group contains the workflow name and the branch name. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - test: - name: Specs with Coverage - Ruby ${{ matrix.ruby }} ${{matrix.gemfile}} ${{ matrix.name_extra || '' }} - env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps - BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile - if: "!contains(github.event.commits[0].message, '[ci skip]') && !contains(github.event.commits[0].message, '[skip ci]')" - strategy: - fail-fast: false - matrix: - experimental: [false] - gemfile: - - a7 - rubygems: - - latest - bundler: - - latest - ruby: - - "2.7" - - runs-on: ubuntu-latest - continue-on-error: ${{ matrix.experimental || endsWith(matrix.ruby, 'head') }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install cURL Headers - run: | - sudo apt-get update - sudo apt-get -y --fix-missing install libcurl4-openssl-dev - - - uses: amancevice/setup-code-climate@v0 - name: CodeClimate Install - if: matrix.ruby == '2.7' && github.event_name != 'pull_request' && always() - with: - cc_test_reporter_id: ${{ secrets.CC_TEST_REPORTER_ID }} - - - name: Setup Ruby & Bundle - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - rubygems: ${{ matrix.rubygems }} - bundler: ${{ matrix.bundler }} - bundler-cache: true - - - name: CodeClimate Pre-build Notification - run: cc-test-reporter before-build - if: matrix.ruby == '2.7' && github.event_name != 'pull_request' && always() - continue-on-error: ${{ matrix.experimental != 'false' }} - - - name: Run tests - run: bundle exec rake test - - - name: CodeClimate Post-build Notification - run: cc-test-reporter after-build - if: matrix.ruby == '2.7' && github.event_name != 'pull_request' && always() - continue-on-error: ${{ matrix.experimental != 'false' }} - - - name: Code Coverage Summary Report - uses: irongut/CodeCoverageSummary@v1.2.0 - with: - filename: ./coverage/coverage.xml - badge: true - fail_below_min: true - format: markdown - hide_branch_rate: true - hide_complexity: true - indicators: true - output: both - thresholds: '78 40' - continue-on-error: ${{ matrix.experimental != 'false' }} - - - name: Add Coverage PR Comment - uses: marocchino/sticky-pull-request-comment@v2 - if: matrix.ruby == '2.7' && always() - with: - recreate: true - path: code-coverage-results.md - continue-on-error: ${{ matrix.experimental != 'false' }} - - - name: Coveralls - uses: coverallsapp/github-action@master - if: matrix.ruby == '2.7' && github.event_name != 'pull_request' && always() - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - continue-on-error: ${{ matrix.experimental != 'false' }} - -# Using the codecov gem instead. -# - name: CodeCov -# uses: codecov/codecov-action@v2 -# if: matrix.ruby == '2.7' && github.event_name != 'pull_request' && always() -# with: -# files: ./coverage/coverage.xml -# flags: unittests -# name: codecov-upload -# fail_ci_if_error: true -# continue-on-error: ${{ matrix.experimental != 'false' }} diff --git a/.github/workflows/heads.yml b/.github/workflows/heads.yml deleted file mode 100644 index 268ceb6e..00000000 --- a/.github/workflows/heads.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: Heads - -on: - push: - branches: - - 'main' - - '*-maintenance' - - '*-dev' - - '*-stable' - tags: - - '!*' # Do not execute on tags - pull_request: - branches: - - '*' - # Allow manually triggering the workflow. - workflow_dispatch: - -# Cancels all previous workflow runs for the same branch that have not yet completed. -concurrency: - # The concurrency group contains the workflow name and the branch name. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - test: - name: Specs - Ruby ${{ matrix.ruby }} ${{matrix.gemfile}} ${{ matrix.name_extra || '' }} - env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps - BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile - if: "!contains(github.event.commits[0].message, '[ci skip]') && !contains(github.event.commits[0].message, '[skip ci]')" - strategy: - fail-fast: false - matrix: - experimental: [true] - gemfile: - - a7 - rubygems: - - latest - bundler: - - latest - ruby: - - truffleruby+graalvm-head - - truffleruby-head - - ruby-head - - runs-on: ubuntu-latest - continue-on-error: ${{ matrix.experimental || endsWith(matrix.ruby, 'head') }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Install cURL Headers - run: | - sudo apt-get update - sudo apt-get -y --fix-missing install libcurl4-openssl-dev - - name: Setup Ruby & Bundle - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - rubygems: ${{ matrix.rubygems }} - bundler: ${{ matrix.bundler }} - bundler-cache: true - - name: Run tests - run: bundle exec rake test diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml deleted file mode 100644 index 04d64aa8..00000000 --- a/.github/workflows/macos.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: MacOS - -on: - push: - branches: - - 'main' - - '*-maintenance' - - '*-dev' - - '*-stable' - tags: - - '!*' # Do not execute on tags - pull_request: - branches: - - '*' - # Allow manually triggering the workflow. - workflow_dispatch: - -# Cancels all previous workflow runs for the same branch that have not yet completed. -concurrency: - # The concurrency group contains the workflow name and the branch name. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - test: - name: Specs - Ruby ${{ matrix.ruby }} ${{matrix.gemfile}} ${{ matrix.name_extra || '' }} - env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps - BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile - if: "!contains(github.event.commits[0].message, '[ci skip]') && !contains(github.event.commits[0].message, '[skip ci]')" - strategy: - fail-fast: false - matrix: - experimental: [true] - gemfile: - - a7 - rubygems: - - latest - bundler: - - latest - ruby: - - "2.7" - - "3.0" - - "3.1" - - truffleruby - - runs-on: macos-latest - continue-on-error: ${{ matrix.experimental || endsWith(matrix.ruby, 'head') }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Setup Ruby & Bundle - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - rubygems: ${{ matrix.rubygems }} - bundler: ${{ matrix.bundler }} - bundler-cache: true - - name: Run tests - run: bundle exec rake test diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml deleted file mode 100644 index 954363b7..00000000 --- a/.github/workflows/style.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Code Style Checks - -on: - push: - branches: - - 'main' - - '*-maintenance' - - '*-dev' - - '*-stable' - tags: - - '!*' # Do not execute on tags - pull_request: - branches: - - '*' - -jobs: - rubocop: - name: Rubocop - env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps - BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile - if: "!contains(github.event.commits[0].message, '[ci skip]') && !contains(github.event.commits[0].message, '[skip ci]')" - strategy: - fail-fast: false - matrix: - experimental: [false] - gemfile: - - a7 - rubygems: - - latest - bundler: - - latest - ruby: - - "2.7" - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Install cURL Headers - run: | - sudo apt-get update - sudo apt-get -y --fix-missing install libcurl4-openssl-dev - - name: Setup Ruby & Bundle - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - rubygems: ${{ matrix.rubygems }} - bundler: ${{ matrix.bundler }} - bundler-cache: true - - name: Run Rubocop - run: bundle exec rubocop -DESP diff --git a/.github/workflows/supported.yml b/.github/workflows/supported.yml deleted file mode 100644 index 4108907c..00000000 --- a/.github/workflows/supported.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: Official Support - -on: - push: - branches: - - 'main' - - '*-maintenance' - - '*-dev' - - '*-stable' - tags: - - '!*' # Do not execute on tags - pull_request: - branches: - - '*' - # Allow manually triggering the workflow. - workflow_dispatch: - -# Cancels all previous workflow runs for the same branch that have not yet completed. -concurrency: - # The concurrency group contains the workflow name and the branch name. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - test: - name: Specs - Ruby ${{ matrix.ruby }} ${{matrix.gemfile}} ${{ matrix.name_extra || '' }} - env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps - BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile - if: "!contains(github.event.commits[0].message, '[ci skip]') && !contains(github.event.commits[0].message, '[skip ci]')" - strategy: - fail-fast: false - matrix: - experimental: [false] - rubygems: - - latest - bundler: - - latest - gemfile: - - a6 - - a7 - ruby: - - "2.7" - - "3.0" - - "3.1" - exclude: - - ruby: "3.0" - gemfile: "a7" - - ruby: "3.1" - gemfile: "a5" - - ruby: "3.1" - gemfile: "a6" - - runs-on: ubuntu-latest - continue-on-error: ${{ matrix.experimental || endsWith(matrix.ruby, 'head') }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Install cURL Headers - run: | - sudo apt-get update - sudo apt-get -y --fix-missing install libcurl4-openssl-dev - - name: Setup Ruby & Bundle - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - rubygems: ${{ matrix.rubygems }} - bundler: ${{ matrix.bundler }} - bundler-cache: true - - name: Run tests - run: bundle exec rake test diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml deleted file mode 100644 index 1ba89b53..00000000 --- a/.github/workflows/windows.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Windows - -on: - push: - branches: - - 'main' - - '*-maintenance' - - '*-dev' - - '*-stable' - tags: - - '!*' # Do not execute on tags - pull_request: - branches: - - '*' - # Allow manually triggering the workflow. - workflow_dispatch: - -# Cancels all previous workflow runs for the same branch that have not yet completed. -concurrency: - # The concurrency group contains the workflow name and the branch name. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - test: - name: Specs - Ruby ${{ matrix.ruby }} ${{matrix.gemfile}} ${{ matrix.name_extra || '' }} - env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps - BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile - if: "!contains(github.event.commits[0].message, '[ci skip]') && !contains(github.event.commits[0].message, '[skip ci]')" - strategy: - fail-fast: false - matrix: - experimental: [true] - gemfile: - - a7 - rubygems: - - latest - bundler: - - latest - ruby: - - "2.7" - - "3.0" - - "3.1" - - runs-on: windows-latest - continue-on-error: ${{ matrix.experimental || endsWith(matrix.ruby, 'head') }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Setup Ruby & Bundle - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - rubygems: ${{ matrix.rubygems }} - bundler: ${{ matrix.bundler }} - bundler-cache: true - - name: Run tests - run: bundle exec rake test diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 892683ab..00000000 --- a/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.bundle -Gemfile.lock -coverage -*.gem - -gemfiles/*.lock -/.tool-versions -/.idea/ diff --git a/.overcommit.yml b/.overcommit.yml deleted file mode 100644 index 2b948875..00000000 --- a/.overcommit.yml +++ /dev/null @@ -1,31 +0,0 @@ -# Use this file to configure the Overcommit hooks you wish to use. This will -# extend the default configuration defined in: -# https://github.com/sds/overcommit/blob/master/config/default.yml -# -# At the topmost level of this YAML file is a key representing type of hook -# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can -# customize each hook, such as whether to only run it on certain files (via -# `include`), whether to only display output if it fails (via `quiet`), etc. -# -# For a complete list of hooks, see: -# https://github.com/sds/overcommit/tree/master/lib/overcommit/hook -# -# For a complete list of options that you can use to customize hooks, see: -# https://github.com/sds/overcommit#configuration -# -# Uncomment the following lines to make the configuration take effect. - -PreCommit: -# RuboCop: -# enabled: true -# on_warn: fail # Treat all warnings as failures - - TrailingWhitespace: - enabled: true - -PostCheckout: - ALL: # Special hook name that customizes all hooks of this type - quiet: true # Change all post-checkout hooks to only display output on failure -# -# IndexTags: -# enabled: true # Generate a tags file with `ctags` each time HEAD changes diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index 1206d111..00000000 --- a/.rubocop.yml +++ /dev/null @@ -1,44 +0,0 @@ -inherit_from: .rubocop_todo.yml - -inherit_gem: - rubocop-lts: rubocop-lts.yml - -require: - - 'rubocop-md' - - 'rubocop-minitest' - - 'rubocop-packaging' - - 'rubocop-performance' - - 'rubocop-rake' - - 'rubocop-thread_safety' - -AllCops: - DisplayCopNames: true # Display the name of the failing cops - -Layout/DotPosition: - Enabled: true - EnforcedStyle: trailing -Metrics/BlockLength: - IgnoredMethods: - - context - - describe - - it - - shared_context - - shared_examples - - shared_examples_for -Style/StringLiterals: - Enabled: true - EnforcedStyle: double_quotes -Style/StringLiteralsInInterpolation: - Enabled: true - EnforcedStyle: double_quotes - -Lint/RaiseException: # (0.81) - Enabled: true -Lint/StructNewOverride: # (0.81) - Enabled: true -Style/HashEachMethods: # (0.80) - Enabled: true -Style/HashTransformKeys: # (0.80) - Enabled: true -Style/HashTransformValues: # (0.80) - Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index 06969419..00000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,114 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2022年08月23日 21:37:33 UTC using RuboCop version 1.30.1. -# 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: AllowComments. -Lint/EmptyWhen: - Exclude: - - 'lib/oauth/consumer.rb' - -# Offense count: 2 -# Configuration parameters: AllowKeywordBlockArguments. -Lint/UnderscorePrefixedVariableName: - Exclude: - - 'lib/oauth/consumer.rb' - -# Offense count: 38 -# Configuration parameters: IgnoredMethods, CountRepeatedAttributes. -Metrics/AbcSize: - Max: 62 - -# Offense count: 8 -# Configuration parameters: CountComments, CountAsOne. -Metrics/ClassLength: - Max: 302 - -# Offense count: 8 -# Configuration parameters: IgnoredMethods. -Metrics/CyclomaticComplexity: - Max: 18 - -# Offense count: 66 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. -Metrics/MethodLength: - Max: 43 - -# Offense count: 1 -# Configuration parameters: Max, CountKeywordArgs. -Metrics/ParameterLists: - MaxOptionalParameters: 4 - -# Offense count: 7 -# Configuration parameters: IgnoredMethods. -Metrics/PerceivedComplexity: - Max: 20 - -# Offense count: 39 -Minitest/MultipleAssertions: - Max: 18 - -# Offense count: 1 -# Configuration parameters: EnforcedStyleForLeadingUnderscores. -# SupportedStylesForLeadingUnderscores: disallowed, required, optional -Naming/MemoizedInstanceVariableName: - Exclude: - - 'lib/oauth/client/em_http.rb' - -# Offense count: 2 -Style/ClassVars: - Exclude: - - 'lib/oauth/consumer.rb' - - 'lib/oauth/server.rb' - -# Offense count: 60 -# Configuration parameters: AllowedConstants. -Style/Documentation: - Enabled: false - -# Offense count: 2 -# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals. -Style/GuardClause: - Exclude: - - 'lib/oauth/consumer.rb' - - 'lib/oauth/signature/base.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/IfUnlessModifier: - Exclude: - - 'bin/bundle' - - 'lib/oauth/request_proxy/net_http.rb' - -# Offense count: 2 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: InverseMethods, InverseBlocks. -Style/InverseMethods: - Exclude: - - 'lib/oauth/request_proxy/base.rb' - -# Offense count: 1 -ThreadSafety/ClassAndModuleAttributes: - Exclude: - - 'lib/oauth/client/action_controller_request.rb' - -# Offense count: 6 -ThreadSafety/InstanceVariableInClassMethod: - Exclude: - - 'lib/oauth/client/action_controller_request.rb' - - 'lib/oauth/request_proxy.rb' - - 'lib/oauth/signature.rb' - - 'lib/oauth/signature/base.rb' - -# Offense count: 76 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns. -# URISchemes: http, https -# AllowedPatterns: (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#), (?-mix:^\#) -# IgnoredPatterns: (?-mix:^\#) -Layout/LineLength: - Max: 429 diff --git a/.simplecov b/.simplecov deleted file mode 100644 index c912b856..00000000 --- a/.simplecov +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -# To get coverage -# On Local, default (HTML) output, it just works, coverage is turned on: -# bundle exec rspec spec -# On Local, all output formats: -# COVER_ALL=true bundle exec rspec spec -# -# On CI, all output formats, the ENV variables CI is always set, -# and COVER_ALL, and CI_CODECOV, are set in the coverage.yml workflow only, -# so coverage only runs in that workflow, and outputs all formats. -# - -if RUN_COVERAGE - SimpleCov.start do - enable_coverage :branch - primary_coverage :branch - add_filter "test" - add_filter "lib/oauth/version.rb" - track_files "**/*.rb" - - if ALL_FORMATTERS - command_name "#{ENV.fetch("GITHUB_WORKFLOW", - nil)} Job #{ENV.fetch("GITHUB_RUN_ID", nil)}:#{ENV.fetch("GITHUB_RUN_NUMBER", nil)}" - else - formatter SimpleCov::Formatter::HTMLFormatter - end - - minimum_coverage(65) - end -else - puts "Not running coverage on #{RUBY_ENGINE} #{RUBY_VERSION}" -end diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 5ec08f48..00000000 --- a/Gemfile +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -source "https://rubygems.org" - -gemspec - -git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } - -# Curb has trouble building native extentions on Windows platform -curb = !Gem.win_platform? - -gem "pry", platforms: %i[mri] -platforms :mri do - gem "codecov", "~> 0.6" # For CodeCov - gem "overcommit", "~> 0.58" - gem "rubocop-md" - gem "rubocop-minitest" - gem "rubocop-packaging" - gem "rubocop-performance" - gem "rubocop-rake" - gem "rubocop-thread_safety" - gem "simplecov", "~> 0.21", require: false - gem "simplecov-cobertura" # XML for Jenkins - gem "simplecov-json" # For CodeClimate - gem "simplecov-lcov", "~> 0.8", require: false - - # Add `byebug` to your code where you want to drop to REPL, and add DEBUG=true when running tests - gem "byebug" - # WebMock is known to work with Curb>= 0.7.16, < 1.1, except versions 0.8.7 - gem "curb", [">= 0.7.16", "< 1.1", "!= 0.8.7"] if curb - gem "pry-byebug" -end - -### deps for documentation and rdoc.info -group :documentation do - gem "github-markup", platform: :mri - gem "redcarpet", platform: :mri - gem "yard", require: false -end diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/Rakefile b/Rakefile deleted file mode 100644 index 071cccc9..00000000 --- a/Rakefile +++ /dev/null @@ -1,23 +0,0 @@ -# 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.verbose = true -end - -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] diff --git a/TODO b/TODO deleted file mode 100644 index e5207def..00000000 --- a/TODO +++ /dev/null @@ -1,32 +0,0 @@ -Common use-cases should be streamlined: - -* I have a URL that I want to sign (given consumer key/secret, optional - token/secret, optional nonce/timestamp). -* I have a URL that I want to sign AND I want to see what the components - (e.g. signature base string, etc.) are while it's being signed (i.e. verbose - signing). -* I have a URL that I want to sign and I only want the signature. -* I have a URL that I want to sign and I want something suitable to put in - {the header, the querystring, XMPP}. -* I want to make a query to an OAuth-enabled web service (with sensible - errors, if available). -* I want to host an OAuth-enabled web service. -* I want to test my OAuth-enabled web service (i.e. test helpers) - -Example applications for: -* Ning -* Fire Eagle -* Google (blogger, contacts) -* Twitter -* YOS / YQL -* Netflix - -In addition to providing best practices of use, these can also be part of -the pre-release checks to make sure that there have been no regressions. - -Random TODOs: -* finish CLI -* sensible Exception hierarchy -* Tokens as Modules -* don't tie to Net::HTTP -* Take a look at Curb HTTP Verbs \ No newline at end of file diff --git a/bin/bundle b/bin/bundle deleted file mode 100755 index 52c61aaf..00000000 --- a/bin/bundle +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'bundle' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "rubygems" - -m = Module.new do - module_function - - def invoked_as_script? - File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__) - end - - def env_var_version - ENV.fetch("BUNDLER_VERSION", nil) - end - - def cli_arg_version - return unless invoked_as_script? # don't want to hijack other binstubs - return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` - - bundler_version = nil - update_index = nil - ARGV.each_with_index do |a, i| - bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN - next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/o - - bundler_version = Regexp.last_match(1) - update_index = i - end - bundler_version - end - - def gemfile - gemfile = ENV.fetch("BUNDLE_GEMFILE", nil) - return gemfile if gemfile && !gemfile.empty? - - File.expand_path("../Gemfile", __dir__) - end - - def lockfile - lockfile = - case File.basename(gemfile) - when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) - else "#{gemfile}.lock" - end - File.expand_path(lockfile) - end - - def lockfile_version - return unless File.file?(lockfile) - - lockfile_contents = File.read(lockfile) - return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/o - - Regexp.last_match(1) - end - - def bundler_requirement - @bundler_requirement ||= - env_var_version || cli_arg_version || - bundler_requirement_for(lockfile_version) - end - - def bundler_requirement_for(version) - return "#{Gem::Requirement.default}.a" unless version - - bundler_gem_version = Gem::Version.new(version) - - requirement = bundler_gem_version.approximate_recommendation - - return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0") - - requirement += ".a" if bundler_gem_version.prerelease? - - requirement - end - - def load_bundler! - ENV["BUNDLE_GEMFILE"] ||= gemfile - - activate_bundler - end - - def activate_bundler - gem_error = activation_error_handling do - gem "bundler", bundler_requirement - end - return if gem_error.nil? - - require_error = activation_error_handling do - require "bundler/version" - end - if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) - return - end - - warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" - exit 42 - end - - def activation_error_handling - yield - nil - rescue StandardError, LoadError => e - e - end -end - -m.load_bundler! - -load Gem.bin_path("bundler", "bundle") if m.invoked_as_script? diff --git a/bin/rake b/bin/rake deleted file mode 100755 index 02376ade..00000000 --- a/bin/rake +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'rake' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) - -bundle_binstub = File.expand_path("bundle", __dir__) - -if File.file?(bundle_binstub) - if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300)) - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("rake", "rake") diff --git a/bin/rubocop b/bin/rubocop deleted file mode 100755 index f8c5cfbf..00000000 --- a/bin/rubocop +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'rubocop' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) - -bundle_binstub = File.expand_path("bundle", __dir__) - -if File.file?(bundle_binstub) - if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300)) - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("rubocop", "rubocop") diff --git a/docs/images/logo/Oauth_logo.svg b/docs/images/logo/Oauth_logo.svg deleted file mode 100644 index 00d25690..00000000 --- a/docs/images/logo/Oauth_logo.svg +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/images/logo/README.txt b/docs/images/logo/README.txt deleted file mode 100644 index ee6d6331..00000000 --- a/docs/images/logo/README.txt +++ /dev/null @@ -1,17 +0,0 @@ -The OAuth 1.0 Logo - Oauth_logo.svg - -https://commons.wikimedia.org/wiki/File:Oauth_logo.svg - -Chris Messina, CC BY-SA 3.0, via Wikimedia Commons - - - - -image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/twitter.rb b/examples/twitter.rb deleted file mode 100755 index 3df2a465..00000000 --- a/examples/twitter.rb +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env ruby -r rubygems -# frozen_string_literal: true - -# -# ./twitter.rb --consumer-key --consumer-secret - -require "oauth" -require "optparse" -require "json" -require "pp" - -options = {} - -option_parser = OptionParser.new do |opts| - opts.banner = "Usage: #{$PROGRAM_NAME} [options] " - - opts.on("--consumer-key KEY", "Specifies the consumer key to use.") do |v| - options[:consumer_key] = v - end - - opts.on("--consumer-secret SECRET", "Specifies the consumer secret to use.") do |v| - options[:consumer_secret] = v - end -end - -option_parser.parse! -query = ARGV.pop -query = $stdin.read if query == "-" - -if options[:consumer_key].nil? || options[:consumer_secret].nil? || query.nil? - puts option_parser.help - exit 1 -end - -consumer = OAuth::Consumer.new \ - options[:consumer_key], - options[:consumer_secret], - site: "https://api.twitter.com" - -access_token = OAuth::AccessToken.new(consumer) - -response = access_token.request(:get, "/1.1/statuses/show/#{OAuth::Helper.escape(query)}.json") -rsp = JSON.parse(response.body) -pp rsp diff --git a/examples/yql.rb b/examples/yql.rb deleted file mode 100755 index 13f8abab..00000000 --- a/examples/yql.rb +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env ruby -r rubygems -# frozen_string_literal: true - -# Sample queries: -# ./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" - -options = {} - -option_parser = OptionParser.new do |opts| - opts.banner = "Usage: #{$PROGRAM_NAME} [options] " - - opts.on("--consumer-key KEY", "Specifies the consumer key to use.") do |v| - options[:consumer_key] = v - end - - opts.on("--consumer-secret SECRET", "Specifies the consumer secret to use.") do |v| - options[:consumer_secret] = v - end -end - -option_parser.parse! -query = ARGV.pop -query = $stdin.read if query == "-" - -if options[:consumer_key].nil? || options[:consumer_secret].nil? || query.nil? - puts option_parser.help - exit 1 -end - -consumer = OAuth::Consumer.new \ - options[:consumer_key], - options[:consumer_secret], - site: "http://query.yahooapis.com" - -access_token = OAuth::AccessToken.new(consumer) - -response = access_token.request(:get, "/v1/yql?q=#{OAuth::Helper.escape(query)}&format=json") -rsp = JSON.parse(response.body) -pp rsp diff --git a/gemfiles/README.md b/gemfiles/README.md deleted file mode 100644 index 076c7059..00000000 --- a/gemfiles/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# History - -This is a ruby library which is intended to be used in creating Ruby Consumer -and Service Provider applications. It is NOT a Rails plugin, but could easily -be used for the foundation for such a Rails plugin. - -This gem was originally extracted from @pelle's [oauth-plugin](https://github.com/pelle/oauth-plugin) -gem. After extraction that gem was made to depend on this gem. - -Unfortunately, this gem does have some Rails related bits that are -**optional** to load. You don't need Rails! The Rails bits may be pulled out -into a separate gem after the release of version 1.0 of this gem. - -These `gemfiles` help with testing this gem against various versions of Rails-ish-ness. - -```ruby -gem "actionpack", [">= 6", "< 8"] -``` - -# *.gemfile Naming - -In the naming of gemfiles, we will use the below shorthand for actionpack and version - -| Gem | Version | Gemfile | -|------------|---------|------------| -| actionpack | ~> 6.0 | a6.gemfile | -| actionpack | ~> 7.0 | a7.gemfile | - -# References - -Compatibility Matrix for Ruby and Rails: -* https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html diff --git a/gemfiles/a6.gemfile b/gemfiles/a6.gemfile deleted file mode 100644 index d6a1d29a..00000000 --- a/gemfiles/a6.gemfile +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -source "https://rubygems.org" - -# See README.md in this directory - -gem "actionpack", "~> 6.0" - -eval_gemfile "../Gemfile" diff --git a/gemfiles/a7.gemfile b/gemfiles/a7.gemfile deleted file mode 100644 index d2613f79..00000000 --- a/gemfiles/a7.gemfile +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -source "https://rubygems.org" - -# See README.md in this directory - -gem "actionpack", "~> 7.0" - -eval_gemfile "../Gemfile" diff --git a/lib/oauth.rb b/lib/oauth.rb deleted file mode 100644 index de0d4d11..00000000 --- a/lib/oauth.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -# third party gems -require "snaky_hash" -require "version_gem" - -require "oauth/version" - -require "oauth/oauth" - -require "oauth/client/helper" -require "oauth/signature/plaintext" -require "oauth/signature/hmac/sha1" -require "oauth/signature/hmac/sha256" -require "oauth/signature/rsa/sha1" -require "oauth/request_proxy/mock_request" - -OAuth::Version.class_eval do - extend VersionGem::Basic -end diff --git a/lib/oauth/client.rb b/lib/oauth/client.rb deleted file mode 100644 index 2e947902..00000000 --- a/lib/oauth/client.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true - -module OAuth - module Client - end -end diff --git a/lib/oauth/client/action_controller_request.rb b/lib/oauth/client/action_controller_request.rb deleted file mode 100644 index 430b0b76..00000000 --- a/lib/oauth/client/action_controller_request.rb +++ /dev/null @@ -1,67 +0,0 @@ -# frozen_string_literal: true - -if defined? ActionDispatch - 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" -end - -module ActionController - class Base - if defined? ActionDispatch - def process_with_new_base_test(request, response = nil) - request.apply_oauth! if request.respond_to?(:apply_oauth!) - super(request, response) - end - else - def process_with_oauth(request, response = nil) - request.apply_oauth! if request.respond_to?(:apply_oauth!) - process_without_oauth(request, response) - end - alias_method_chain :process, :oauth - end - end - - class TestRequest - class << self - attr_writer :use_oauth - end - - def self.use_oauth? - @use_oauth - end - - def configure_oauth(consumer = nil, token = nil, options = {}) - @oauth_options = { consumer: consumer, - token: token, - scheme: "header", - signature_method: nil, - nonce: nil, - timestamp: nil }.merge(options) - end - - def apply_oauth! - return unless ActionController::TestRequest.use_oauth? && @oauth_options - - @oauth_helper = OAuth::Client::Helper.new(self, - @oauth_options.merge(request_uri: (respond_to?(:fullpath) ? fullpath : request_uri))) - @oauth_helper.amend_user_agent_header(env) - - send("set_oauth_#{@oauth_options[:scheme]}") - end - - def set_oauth_header - env["Authorization"] = @oauth_helper.header - end - - def set_oauth_parameters - @query_parameters = @oauth_helper.parameters_with_oauth - @query_parameters.merge!(oauth_signature: @oauth_helper.signature) - end - - def set_oauth_query_string; end - end -end diff --git a/lib/oauth/client/em_http.rb b/lib/oauth/client/em_http.rb deleted file mode 100644 index 9f4fa73e..00000000 --- a/lib/oauth/client/em_http.rb +++ /dev/null @@ -1,119 +0,0 @@ -# frozen_string_literal: true - -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. -module EventMachine - class HttpClient - attr_reader :oauth_helper - - # Add the OAuth information to an HTTP request. Depending on the options[:scheme] setting - # this may add a header, additional query string parameters, or additional POST body parameters. - # The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+ - # header. - # - # * http - Configured Net::HTTP instance, ignored in this scenario except for getting host. - # * consumer - OAuth::Consumer instance - # * token - OAuth::Token instance - # * options - Request-specific options (e.g. +request_uri+, +consumer+, +token+, +scheme+, - # +signature_method+, +nonce+, +timestamp+) - # - # This method also modifies the User-Agent header to add the OAuth gem version. - # - # See Also: {OAuth core spec version 1.0, section 5.4.1}[http://oauth.net/core/1.0#rfc.section.5.4.1] - def oauth!(http, consumer = nil, token = nil, options = {}) - options = { request_uri: normalized_oauth_uri(http), - consumer: consumer, - token: token, - scheme: "header", - signature_method: nil, - nonce: nil, - timestamp: nil }.merge(options) - - @oauth_helper = OAuth::Client::Helper.new(self, options) - __send__(:"set_oauth_#{options[:scheme]}") - end - - # Create a string suitable for signing for an HTTP request. This process involves parameter - # normalization as specified in the OAuth specification. The exact normalization also depends - # on the options[:scheme] being used so this must match what will be used for the request - # itself. The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+ - # header. - # - # * http - Configured Net::HTTP instance - # * consumer - OAuth::Consumer instance - # * token - OAuth::Token instance - # * options - Request-specific options (e.g. +request_uri+, +consumer+, +token+, +scheme+, - # +signature_method+, +nonce+, +timestamp+) - # - # See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1] - def signature_base_string(http, consumer = nil, token = nil, options = {}) - options = { request_uri: normalized_oauth_uri(http), - consumer: consumer, - token: token, - scheme: "header", - signature_method: nil, - nonce: nil, - timestamp: nil }.merge(options) - - OAuth::Client::Helper.new(self, options).signature_base_string - end - - # This code was lifted from the em-http-request because it was removed from - # the gem June 19, 2010 - # see: http://github.com/igrigorik/em-http-request/commit/d536fc17d56dbe55c487eab01e2ff9382a62598b - def normalize_uri - @normalized_uri ||= begin - uri = @conn.dup - encoded_query = encode_query(@conn, @req[:query]) - path, query = encoded_query.split("?", 2) - uri.query = query unless encoded_query.empty? - uri.path = path - uri - end - end - - protected - - def combine_query(path, query, uri_query) - combined_query = if query.is_a?(Hash) - query.map { |k, v| encode_param(k, v) }.join("&") - else - query.to_s - end - combined_query = [combined_query, uri_query].reject(&:empty?).join("&") unless uri_query.to_s.empty? - combined_query.to_s.empty? ? path : "#{path}?#{combined_query}" - end - - # Since we expect to get the host etc details from the http instance (...), - # we create a fake url here. Surely this is a horrible, horrible idea? - def normalized_oauth_uri(http) - uri = URI.parse(normalize_uri.path) - uri.host = http.address - uri.port = http.port - - uri.scheme = if http.respond_to?(:use_ssl?) && http.use_ssl? - "https" - else - "http" - end - uri.to_s - end - - def set_oauth_header - req[:head] ||= {} - req[:head].merge!("Authorization" => @oauth_helper.header) - end - - def set_oauth_body - 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" - end - end -end diff --git a/lib/oauth/client/helper.rb b/lib/oauth/client/helper.rb deleted file mode 100644 index 8e30a036..00000000 --- a/lib/oauth/client/helper.rb +++ /dev/null @@ -1,102 +0,0 @@ -# frozen_string_literal: true - -require "oauth/client" -require "oauth/consumer" -require "oauth/helper" -require "oauth/token" -require "oauth/signature/hmac/sha1" - -module OAuth - module Client - class Helper - include OAuth::Helper - - def initialize(request, options = {}) - @request = request - @options = options - @options[:signature_method] ||= "HMAC-SHA1" - end - - attr_reader :options - - def nonce - options[:nonce] ||= generate_key - end - - def timestamp - options[:timestamp] ||= generate_timestamp - end - - 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] - } - allowed_empty_params = options[:allow_empty_params] - if allowed_empty_params != true && !allowed_empty_params.is_a?(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 - end - - def signature(extra_options = {}) - OAuth::Signature.sign(@request, { uri: options[:request_uri], - consumer: options[:consumer], - token: options[:token], - unsigned_parameters: options[:unsigned_parameters] }.merge(extra_options)) - end - - def signature_base_string(extra_options = {}) - OAuth::Signature.signature_base_string(@request, { uri: options[:request_uri], - consumer: options[:consumer], - token: options[:token], - parameters: oauth_parameters }.merge(extra_options)) - end - - def token_request? - @options[:token_request].eql?(true) - end - - def hash_body - @options[:body_hash] = OAuth::Signature.body_hash(@request, parameters: oauth_parameters) - end - - def amend_user_agent_header(headers) - @oauth_ua_string ||= "OAuth gem v#{OAuth::Version::VERSION}" - # Net::HTTP in 1.9 appends Ruby - if headers["User-Agent"] && headers["User-Agent"] != "Ruby" - headers["User-Agent"] += " (#{@oauth_ua_string})" - else - headers["User-Agent"] = @oauth_ua_string - end - end - - def header - parameters = oauth_parameters - parameters["oauth_signature"] = signature(options.merge(parameters: parameters)) - - header_params_str = parameters.sort.map { |k, v| "#{k}=\"#{escape(v)}\"" }.join(", ") - - realm = "realm=\"#{options[:realm]}\", " if options[:realm] - "OAuth #{realm}#{header_params_str}" - end - - def parameters - OAuth::RequestProxy.proxy(@request).parameters - end - - def parameters_with_oauth - oauth_parameters.merge(parameters) - end - end - end -end diff --git a/lib/oauth/client/net_http.rb b/lib/oauth/client/net_http.rb deleted file mode 100644 index 8b00f5f7..00000000 --- a/lib/oauth/client/net_http.rb +++ /dev/null @@ -1,128 +0,0 @@ -# frozen_string_literal: true - -require "oauth/helper" -require "oauth/request_proxy/net_http" - -module Net - class HTTPGenericRequest - include OAuth::Helper - - attr_reader :oauth_helper - - # Add the OAuth information to an HTTP request. Depending on the options[:scheme] setting - # this may add a header, additional query string parameters, or additional POST body parameters. - # The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+ - # header. - # - # * http - Configured Net::HTTP instance - # * consumer - OAuth::Consumer instance - # * token - OAuth::Token instance - # * options - Request-specific options (e.g. +request_uri+, +consumer+, +token+, +scheme+, - # +signature_method+, +nonce+, +timestamp+, +body_hash+) - # - # This method also modifies the User-Agent header to add the OAuth gem version. - # - # See Also: {OAuth core spec version 1.0, section 5.4.1}[http://oauth.net/core/1.0#rfc.section.5.4.1], - # {OAuth Request Body Hash 1.0 Draft 4}[http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/drafts/4/spec.html, - # http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html#when_to_include] - def oauth!(http, consumer = nil, token = nil, options = {}) - helper_options = oauth_helper_options(http, consumer, token, options) - @oauth_helper = OAuth::Client::Helper.new(self, helper_options) - @oauth_helper.amend_user_agent_header(self) - @oauth_helper.hash_body if oauth_body_hash_required?(helper_options) - send("set_oauth_#{helper_options[:scheme]}") - end - - # Create a string suitable for signing for an HTTP request. This process involves parameter - # normalization as specified in the OAuth specification. The exact normalization also depends - # on the options[:scheme] being used so this must match what will be used for the request - # itself. The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+ - # header. - # - # * http - Configured Net::HTTP instance - # * consumer - OAuth::Consumer instance - # * token - OAuth::Token instance - # * options - Request-specific options (e.g. +request_uri+, +consumer+, +token+, +scheme+, - # +signature_method+, +nonce+, +timestamp+) - # - # See Also: {OAuth core spec version 1.0, section 5.4.1}[http://oauth.net/core/1.0#rfc.section.5.4.1], - # {OAuth Request Body Hash 1.0 Draft 4}[http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/drafts/4/spec.html, - # http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html#when_to_include] - def signature_base_string(http, consumer = nil, token = nil, options = {}) - helper_options = oauth_helper_options(http, consumer, token, options) - @oauth_helper = OAuth::Client::Helper.new(self, helper_options) - @oauth_helper.hash_body if oauth_body_hash_required?(helper_options) - @oauth_helper.signature_base_string - end - - private - - def oauth_helper_options(http, consumer, token, options) - { request_uri: oauth_full_request_uri(http, options), - consumer: consumer, - token: token, - scheme: "header", - signature_method: nil, - nonce: nil, - timestamp: nil, - body_hash_enabled: true }.merge(options) - end - - def oauth_full_request_uri(http, options) - uri = URI.parse(path) - uri.host = http.address - uri.port = http.port - - if options[:request_endpoint] && options[:site] - is_https = options[:site].match(%r{^https://}) - uri.host = options[:site].gsub(%r{^https?://}, "") - uri.port ||= is_https ? 443 : 80 - end - - uri.scheme = if http.respond_to?(:use_ssl?) && http.use_ssl? - "https" - else - "http" - end - - uri.to_s - end - - def oauth_body_hash_required?(options) - !@oauth_helper.token_request? && request_body_permitted? && !content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded") && options[:body_hash_enabled] - end - - def set_oauth_header - self["Authorization"] = @oauth_helper.header - end - - # FIXME: if you're using a POST body and query string parameters, this method - # will move query string parameters into the body unexpectedly. This may - # cause problems with non-x-www-form-urlencoded bodies submitted to URLs - # containing query string params. If duplicate parameters are present in both - # places, all instances should be included when calculating the signature - # base string. - - def set_oauth_body - # NOTE: OAuth::Helper and @oauth_helper are not the same, despite sharing all methods defined in OAuth::Helper - # see: https://stackoverflow.com/a/53447775/213191 - set_form_data(OAuth::Helper.stringify_keys(@oauth_helper.parameters_with_oauth)) - params_with_sig = @oauth_helper.parameters.merge(oauth_signature: @oauth_helper.signature) - set_form_data(OAuth::Helper.stringify_keys(params_with_sig)) - end - - def set_oauth_query_string - oauth_params_str = @oauth_helper.oauth_parameters.map { |k, v| [escape(k), escape(v)].join("=") }.join("&") - uri = URI.parse(path) - uri.query = if uri.query.to_s == "" - oauth_params_str - else - "#{uri.query}&#{oauth_params_str}" - end - - @path = uri.to_s - - @path << "&oauth_signature=#{escape(oauth_helper.signature)}" - end - end -end diff --git a/lib/oauth/consumer.rb b/lib/oauth/consumer.rb deleted file mode 100644 index 11ab1fcb..00000000 --- a/lib/oauth/consumer.rb +++ /dev/null @@ -1,463 +0,0 @@ -# frozen_string_literal: true - -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"] - else - raise "The SSL CERT provided does not exist." - end - end - - unless defined?(CA_FILE) - CA_FILES = %w[/etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt - /usr/share/curl/curl-ca-bundle.crt].freeze - CA_FILES.each do |ca_file| - if File.exist?(ca_file) - CA_FILE = ca_file - break - end - end - end - CA_FILE = nil unless defined?(CA_FILE) - - @@default_options = SnakyHash::SymbolKeyed.new( - { - # Signature method used by server. Defaults to 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", - - proxy: nil, - # How do we send the oauth values to the server see - # https://oauth.net/core/1.0/#consumer_req_param for more info - # - # Possible values: - # - # :header - via the Authorize header (Default) ( option 1. in spec) - # :body - url form encoded in body of POST request ( option 2. in spec) - # :query_string - via the query part of the url ( option 3. in spec) - scheme: :header, - - # Default http method used for OAuth Token Requests (defaults to :post) - http_method: :post, - - # Add a custom ca_file for consumer - # :ca_file => '/etc/certs.pem' - - # Possible values: - # - # nil, false - no debug output - # true - uses $stdout - # some_value - uses some_value - debug_output: nil, - - # Defaults to producing a body_hash as part of the signature but - # can be disabled since it's not officially part of the OAuth 1.0 - # spec. Possible values are true and false - body_hash_enabled: true, - - oauth_version: "1.0" - } - ) - - attr_accessor :options, :key, :secret - attr_writer :site, :http - - # Create a new consumer instance by passing it a configuration hash: - # - # @consumer = OAuth::Consumer.new(key, secret, { - # :site => "http://term.ie", - # :scheme => :header, - # :http_method => :post, - # :request_token_path => "/oauth/example/request_token.php", - # :access_token_path => "/oauth/example/access_token.php", - # :authorize_path => "/oauth/example/authorize.php", - # :body_hash_enabled => false - # }) - # - # Start the process by requesting a token - # - # @request_token = @consumer.get_request_token - # session[:request_token] = @request_token - # redirect_to @request_token.authorize_url - # - # When user returns create an access_token - # - # @access_token = @request_token.get_access_token - # @photos=@access_token.get('/photos.xml') - # - def initialize(consumer_key, consumer_secret, options = {}) - @key = consumer_key - @secret = consumer_secret - - # ensure that keys are symbols - snaky_options = SnakyHash::SymbolKeyed.new(options) - @options = @@default_options.merge(snaky_options) - end - - # The default http method - def http_method - @http_method ||= @options[:http_method] || :post - end - - def debug_output - @debug_output ||= case @options[:debug_output] - when nil, false - when true - $stdout - else - @options[:debug_output] - end - end - - # The HTTP object for the site. The HTTP Object is what you get when you do Net::HTTP.new - def http - @http ||= create_http - end - - # Contains the root URI for this site - def uri(custom_uri = nil) - if custom_uri - @uri = custom_uri - @http = create_http # yike, oh well. less intrusive this way - else # if no custom passed, we use existing, which, if unset, is set to site uri - @uri ||= URI.parse(site) - end - end - - def get_access_token(request_token, request_options = {}, *arguments, &block) - response = token_request(http_method, (access_token_url? ? access_token_url : access_token_path), request_token, - request_options, *arguments, &block) - OAuth::AccessToken.from_hash(self, response) - end - - # Makes a request to the service for a new OAuth::RequestToken - # - # @request_token = @consumer.get_request_token - # - # To include OAuth parameters: - # - # @request_token = @consumer.get_request_token \ - # :oauth_callback => "http://example.com/cb" - # - # To include application-specific parameters: - # - # @request_token = @consumer.get_request_token({}, :foo => "bar") - # - # TODO oauth_callback should be a mandatory parameter - def get_request_token(request_options = {}, *arguments, &block) - # if oauth_callback wasn't provided, it is assumed that oauth_verifiers - # will be exchanged out of band - request_options[:oauth_callback] ||= OAuth::OUT_OF_BAND unless request_options[:exclude_callback] - - response = if block - token_request( - http_method, - (request_token_url? ? request_token_url : request_token_path), - nil, - request_options, - *arguments, - &block - ) - else - token_request(http_method, (request_token_url? ? request_token_url : request_token_path), nil, - request_options, *arguments) - end - OAuth::RequestToken.from_hash(self, response) - end - - # Creates, signs and performs an http request. - # It's recommended to use the OAuth::Token classes to set this up correctly. - # request_options take precedence over consumer-wide options when signing - # a request. - # arguments are POST and PUT bodies (a Hash, string-encoded parameters, or - # absent), followed by additional HTTP headers. - # - # @consumer.request(:get, '/people', @token, { :scheme => :query_string }) - # @consumer.request(:post, '/people', @token, {}, @person.to_xml, { 'Content-Type' => 'application/xml' }) - # - def request(http_method, path, token = nil, request_options = {}, *arguments) - unless %r{^/}.match?(path) - @http = create_http(path) - _uri = URI.parse(path) - path = "#{_uri.path}#{_uri.query ? "?#{_uri.query}" : ""}" - end - - # override the request with your own, this is useful for file uploads which Net::HTTP does not do - req = create_signed_request(http_method, path, token, request_options, *arguments) - return nil if block_given? && (yield(req) == :done) - - rsp = http.request(req) - # check for an error reported by the Problem Reporting extension - # (https://wiki.oauth.net/ProblemReporting) - # note: a 200 may actually be an error; check for an oauth_problem key to be sure - if !(headers = rsp.to_hash["www-authenticate"]).nil? && - (h = headers.grep(/^OAuth /)).any? && - h.first.include?("oauth_problem") - - # puts "Header: #{h.first}" - - # TODO: doesn't handle broken responses from api.login.yahoo.com - # remove debug code when done - params = OAuth::Helper.parse_header(h.first) - - # puts "Params: #{params.inspect}" - # puts "Body: #{rsp.body}" - - raise OAuth::Problem.new(params.delete("oauth_problem"), rsp, params) - end - - rsp - end - - # Creates and signs an http request. - # It's recommended to use the Token classes to set this up correctly - def create_signed_request(http_method, path, token = nil, request_options = {}, *arguments) - request = create_http_request(http_method, path, *arguments) - sign!(request, token, request_options) - request - end - - # Creates a request and parses the result as url_encoded. This is used internally for the RequestToken and AccessToken requests. - def token_request(http_method, path, token = nil, request_options = {}, *arguments) - request_options[:token_request] ||= true - response = request(http_method, path, token, request_options, *arguments) - case response.code.to_i - - when (200..299) - if block_given? - yield response.body - else - # symbolize keys - # TODO this could be considered unexpected behavior; symbols or not? - # TODO this also drops subsequent values from multi-valued keys - CGI.parse(response.body).each_with_object({}) do |(k, v), h| - h[k.strip.to_sym] = v.first - h[k.strip] = v.first - end - end - when (300..399) - # Parse redirect to follow - uri = URI.parse(response["location"]) - our_uri = URI.parse(site) - - # Guard against infinite redirects - response.error! if uri.path == path && our_uri.host == uri.host - - if uri.path == path && our_uri.host != uri.host - options[:site] = "#{uri.scheme}://#{uri.host}" - @http = create_http - end - - token_request(http_method, uri.path, token, request_options, arguments) - when (400..499) - raise OAuth::Unauthorized, response - else - response.error! - end - end - - # Sign the Request object. Use this if you have an externally generated http request object you want to sign. - def sign!(request, token = nil, request_options = {}) - request.oauth!(http, self, token, options.merge(request_options)) - end - - # Return the signature_base_string - def signature_base_string(request, token = nil, request_options = {}) - request.signature_base_string(http, self, token, options.merge(request_options)) - end - - def site - @options[:site].to_s - end - - def request_endpoint - return nil if @options[:request_endpoint].nil? - - @options[:request_endpoint].to_s - end - - def scheme - @options[:scheme] - end - - def request_token_path - @options[:request_token_path] - end - - def authenticate_path - @options[:authenticate_path] - end - - def authorize_path - @options[:authorize_path] - end - - def access_token_path - @options[:access_token_path] - end - - # TODO: this is ugly, rewrite - def request_token_url - @options[:request_token_url] || (site + request_token_path) - end - - def request_token_url? - @options.key?(:request_token_url) - end - - def authenticate_url - @options[:authenticate_url] || (site + authenticate_path) - end - - def authenticate_url? - @options.key?(:authenticate_url) - end - - def authorize_url - @options[:authorize_url] || (site + authorize_path) - end - - def authorize_url? - @options.key?(:authorize_url) - end - - def access_token_url - @options[:access_token_url] || (site + access_token_path) - end - - def access_token_url? - @options.key?(:access_token_url) - end - - def proxy - @options[:proxy] - end - - protected - - # Instantiates the http object - def create_http(_url = nil) - _url = request_endpoint unless request_endpoint.nil? - - our_uri = if _url.nil? || _url[0] =~ %r{^/} - URI.parse(site) - else - your_uri = URI.parse(_url) - if your_uri.host.nil? - # If the _url is a path, missing the leading slash, then it won't have a host, - # and our_uri *must* have a host, so we parse site instead. - URI.parse(site) - else - your_uri - end - end - - if proxy.nil? - http_object = Net::HTTP.new(our_uri.host, our_uri.port) - else - proxy_uri = proxy.is_a?(URI) ? proxy : URI.parse(proxy) - 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") - - if @options[:no_verify] - http_object.verify_mode = OpenSSL::SSL::VERIFY_NONE - else - ca_file = @options[:ca_file] || CA_FILE - http_object.ca_file = ca_file if ca_file - http_object.verify_mode = OpenSSL::SSL::VERIFY_PEER - http_object.verify_depth = 5 - end - - http_object.read_timeout = http_object.open_timeout = @options[:timeout] || 60 - http_object.open_timeout = @options[:open_timeout] if @options[:open_timeout] - http_object.ssl_version = @options[:ssl_version] if @options[:ssl_version] - http_object.cert = @options[:ssl_client_cert] if @options[:ssl_client_cert] - http_object.key = @options[:ssl_client_key] if @options[:ssl_client_key] - http_object.set_debug_output(debug_output) if debug_output - - http_object - end - - # create the http request object for a given http_method and path - def create_http_request(http_method, path, *arguments) - http_method = http_method.to_sym - - data = arguments.shift if %i[post put patch].include?(http_method) - - # if the base site contains a path, add it now - # 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 - - 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 - when :put - request = Net::HTTP::Put.new(path, headers) - request["Content-Length"] = "0" # Default to 0 - when :patch - request = Net::HTTP::Patch.new(path, headers) - request["Content-Length"] = "0" # Default to 0 - when :get - request = Net::HTTP::Get.new(path, headers) - when :delete - request = Net::HTTP::Delete.new(path, headers) - when :head - request = Net::HTTP::Head.new(path, headers) - else - raise ArgumentError, "Don't know how to handle http_method: :#{http_method}" - end - - if data.is_a?(Hash) - request.body = OAuth::Helper.normalize(data) - request.content_type = "application/x-www-form-urlencoded" - elsif data - if data.respond_to?(:read) - request.body_stream = data - if data.respond_to?(:length) - request["Content-Length"] = data.length.to_s - elsif data.respond_to?(:stat) && data.stat.respond_to?(:size) - request["Content-Length"] = data.stat.size.to_s - else - raise ArgumentError, "Don't know how to send a body_stream that doesn't respond to .length or .stat.size" - end - else - request.body = data.to_s - request["Content-Length"] = request.body.length.to_s - end - end - - request - end - - def marshal_dump(*_args) - { key: @key, secret: @secret, options: @options } - end - - def marshal_load(data) - initialize(data[:key], data[:secret], data[:options]) - end - end -end diff --git a/lib/oauth/errors.rb b/lib/oauth/errors.rb deleted file mode 100644 index 6955469c..00000000 --- a/lib/oauth/errors.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -require "oauth/errors/error" -require "oauth/errors/unauthorized" -require "oauth/errors/problem" diff --git a/lib/oauth/errors/error.rb b/lib/oauth/errors/error.rb deleted file mode 100644 index 82128ff4..00000000 --- a/lib/oauth/errors/error.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true - -module OAuth - class Error < StandardError - end -end diff --git a/lib/oauth/errors/problem.rb b/lib/oauth/errors/problem.rb deleted file mode 100644 index 55e12be2..00000000 --- a/lib/oauth/errors/problem.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module OAuth - class Problem < OAuth::Unauthorized - attr_reader :problem, :params - - def initialize(problem, request = nil, params = {}) - super(request) - @problem = problem - @params = params - end - - def to_s - problem - end - end -end diff --git a/lib/oauth/errors/unauthorized.rb b/lib/oauth/errors/unauthorized.rb deleted file mode 100644 index d9786bb6..00000000 --- a/lib/oauth/errors/unauthorized.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -module OAuth - class Unauthorized < OAuth::Error - attr_reader :request - - def initialize(request = nil) - super() - @request = request - end - - def to_s - return "401 Unauthorized" if request.nil? - - "#{request.code} #{request.message}" - end - end -end diff --git a/lib/oauth/helper.rb b/lib/oauth/helper.rb deleted file mode 100644 index d22e8286..00000000 --- a/lib/oauth/helper.rb +++ /dev/null @@ -1,121 +0,0 @@ -# frozen_string_literal: true - -require "time" -require "openssl" -require "base64" - -module OAuth - module Helper - module_function - - # Escape +value+ by URL encoding all non-reserved character. - # - # See Also: {OAuth core spec version 1.0, section 5.1}[http://oauth.net/core/1.0#rfc.section.5.1] - def escape(value) - _escape(value.to_s.to_str) - rescue ArgumentError - _escape(value.to_s.to_str.force_encoding(Encoding::UTF_8)) - end - - def _escape(string) - URI::DEFAULT_PARSER.escape(string, OAuth::RESERVED_CHARACTERS) - end - - def unescape(value) - 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/, "") - end - - alias generate_nonce generate_key - - def generate_timestamp # :nodoc: - Time.now.to_i.to_s - end - - # Normalize a +Hash+ of parameter values. Parameters are sorted by name, using lexicographical - # byte value ordering. If two or more parameters share the same name, they are sorted by their value. - # Parameters are concatenated in their sorted order into a single string. For each parameter, the name - # is separated from the corresponding value by an "=" character, even if the value is empty. Each - # name-value pair is separated by an "&" character. - # - # See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1] - def normalize(params) - params.sort.map do |k, values| - case values - when Array - # make sure the array has an element so we don't lose the key - values << nil if values.empty? - # multiple values were provided for a single key - if values[0].is_a?(Hash) - normalize_nested_query(values, k) - else - values.sort.collect do |v| - [escape(k), escape(v)].join("=") - end - end - when Hash - normalize_nested_query(values, k) - else - [escape(k), escape(values)].join("=") - end - end * "&" - end - - # Returns a string representation of the Hash like in URL query string - # build_nested_query({:level_1 => {:level_2 => ['value_1','value_2']}}, 'prefix')) - # #=> ["prefix%5Blevel_1%5D%5Blevel_2%5D%5B%5D=value_1", "prefix%5Blevel_1%5D%5Blevel_2%5D%5B%5D=value_2"] - def normalize_nested_query(value, prefix = nil) - case value - when Array - value.map do |v| - normalize_nested_query(v, "#{prefix}[]") - end.flatten.sort - when Hash - value.map do |k, v| - normalize_nested_query(v, prefix ? "#{prefix}[#{k}]" : k) - end.flatten.sort - else - [escape(prefix), escape(value)].join("=") - end - end - - # Parse an Authorization / WWW-Authenticate header into a hash. Takes care of unescaping and - # removing surrounding quotes. Raises a OAuth::Problem if the header is not parsable into a - # valid hash. Does not validate the keys or values. - # - # hash = parse_header(headers['Authorization'] || headers['WWW-Authenticate']) - # hash['oauth_timestamp'] - # #=>"1234567890" - # - def parse_header(header) - # decompose - params = header[6, header.length].split(/[,=&]/) - - # odd number of arguments - must be a malformed header. - raise OAuth::Problem, "Invalid authorization header" if params.size.odd? - - params.map! do |v| - # strip and unescape - val = unescape(v.strip) - # strip quotes - val.sub(/^"(.*)"$/, '1円') - end - - # convert into a Hash - Hash[*params.flatten] - end - - def stringify_keys(hash) - new_h = {} - hash.each do |k, v| - new_h[k.to_s] = v.is_a?(Hash) ? stringify_keys(v) : v - end - new_h - end - end -end diff --git a/lib/oauth/oauth.rb b/lib/oauth/oauth.rb deleted file mode 100644 index de3c71c6..00000000 --- a/lib/oauth/oauth.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -module OAuth - # request tokens are passed between the consumer and the provider out of - # band (i.e. callbacks cannot be used), per section 6.1.1 - OUT_OF_BAND = "oob" - - # required parameters, per sections 6.1.1, 6.3.1, and 7 - PARAMETERS = %w[oauth_callback oauth_consumer_key oauth_token - oauth_signature_method oauth_timestamp oauth_nonce oauth_verifier - oauth_version oauth_signature oauth_body_hash].freeze - - # reserved character regexp, per section 5.1 - RESERVED_CHARACTERS = /[^a-zA-Z0-9\-._~]/.freeze -end diff --git a/lib/oauth/oauth_test_helper.rb b/lib/oauth/oauth_test_helper.rb deleted file mode 100644 index 1b4cda85..00000000 --- a/lib/oauth/oauth_test_helper.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -require "action_controller" -require "action_controller/test_process" - -module OAuth - module OAuthTestHelper - def mock_incoming_request_with_query(request) - incoming = ActionController::TestRequest.new(request.to_hash) - 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 - end - - def mock_incoming_request_with_authorize_header(request) - incoming = ActionController::TestRequest.new - incoming.request_uri = request.path - 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 - end - end -end diff --git a/lib/oauth/request_proxy.rb b/lib/oauth/request_proxy.rb deleted file mode 100644 index 50dfeb04..00000000 --- a/lib/oauth/request_proxy.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module OAuth - module RequestProxy - def self.available_proxies # :nodoc: - @available_proxies ||= {} - end - - def self.proxy(request, options = {}) - return request if request.is_a?(OAuth::RequestProxy::Base) - - klass = available_proxies[request.class] - - # Search for possible superclass matches. - if klass.nil? - request_parent = available_proxies.keys.find { |rc| request.is_a?(rc) } - klass = available_proxies[request_parent] - end - - raise UnknownRequestType, request.class.to_s unless klass - - klass.new(request, options) - end - - class UnknownRequestType < RuntimeError; end - end -end diff --git a/lib/oauth/request_proxy/action_controller_request.rb b/lib/oauth/request_proxy/action_controller_request.rb deleted file mode 100644 index 79a1d30f..00000000 --- a/lib/oauth/request_proxy/action_controller_request.rb +++ /dev/null @@ -1,68 +0,0 @@ -# frozen_string_literal: true - -require "active_support" -require "action_controller" -require "uri" - -require "action_dispatch/http/request" - -module OAuth - module RequestProxy - class ActionControllerRequest < OAuth::RequestProxy::Base - proxies(::ActionDispatch::Request) - - def method - request.method.to_s.upcase - end - - def uri - request.url - end - - def parameters - if options[:clobber_request] - options[:parameters] || {} - else - params = request_params.merge(query_params).merge(header_params) - params.stringify_keys! if params.respond_to?(:stringify_keys!) - params.merge(options[:parameters] || {}) - end - end - - # Override from OAuth::RequestProxy::Base to avoid round-trip - # conversion to Hash or Array and thus preserve the original - # parameter names - def parameters_for_signature - params = [] - params << options[:parameters].to_query if options[:parameters] - - unless options[:clobber_request] - params << header_params.to_query - params << request.query_string unless query_string_blank? - - params << request.raw_post if raw_post_signature? - end - - params. - join("&").split("&"). - reject { |s| s.match(/\A\s*\z/) }. - map { |p| p.split("=").map { |esc| CGI.unescape(esc) } }. - reject { |kv| kv[0] == "oauth_signature" } - end - - def raw_post_signature? - (request.post? || request.put?) && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded") - end - - protected - - def query_params - request.query_parameters - end - - def request_params - request.request_parameters - end - end - end -end diff --git a/lib/oauth/request_proxy/action_dispatch_request.rb b/lib/oauth/request_proxy/action_dispatch_request.rb deleted file mode 100644 index a94141eb..00000000 --- a/lib/oauth/request_proxy/action_dispatch_request.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -require "oauth/request_proxy/rack_request" - -module OAuth - module RequestProxy - class ActionDispatchRequest < OAuth::RequestProxy::RackRequest - proxies ::ActionDispatch::Request - end - end -end diff --git a/lib/oauth/request_proxy/base.rb b/lib/oauth/request_proxy/base.rb deleted file mode 100644 index e175b461..00000000 --- a/lib/oauth/request_proxy/base.rb +++ /dev/null @@ -1,182 +0,0 @@ -# frozen_string_literal: true - -require "oauth/request_proxy" -require "oauth/helper" - -module OAuth - module RequestProxy - class Base - include OAuth::Helper - - def self.proxies(klass) - OAuth::RequestProxy.available_proxies[klass] = self - end - - attr_accessor :request, :options, :unsigned_parameters - - def initialize(request, options = {}) - @request = request - @unsigned_parameters = (options[:unsigned_parameters] || []).map(&:to_s) - @options = options - end - - ## OAuth parameters - - def oauth_callback - parameters["oauth_callback"] - end - - def oauth_consumer_key - parameters["oauth_consumer_key"] - end - - def oauth_nonce - parameters["oauth_nonce"] - end - - def oauth_signature - # TODO: can this be nil? - [parameters["oauth_signature"]].flatten.first || "" - end - - def oauth_signature_method - case parameters["oauth_signature_method"] - when Array - parameters["oauth_signature_method"].first - else - parameters["oauth_signature_method"] - end - end - - def oauth_timestamp - parameters["oauth_timestamp"] - end - - def oauth_token - parameters["oauth_token"] - end - - def oauth_verifier - parameters["oauth_verifier"] - end - - def oauth_version - parameters["oauth_version"] - end - - # TODO: deprecate these - alias consumer_key oauth_consumer_key - alias token oauth_token - alias nonce oauth_nonce - alias timestamp oauth_timestamp - alias signature oauth_signature - alias signature_method oauth_signature_method - - ## Parameter accessors - - def parameters - raise NotImplementedError, "Must be implemented by subclasses" - end - - def parameters_for_signature - parameters.select { |k, _v| !signature_and_unsigned_parameters.include?(k) } - end - - def oauth_parameters - parameters.select { |k, v| OAuth::PARAMETERS.include?(k) && !v.nil? && v != "" } - end - - def non_oauth_parameters - parameters.select { |k, _v| !OAuth::PARAMETERS.include?(k) } - end - - def signature_and_unsigned_parameters - unsigned_parameters + ["oauth_signature"] - end - - # See 9.1.2 in specs - def normalized_uri - u = URI.parse(uri) - "#{u.scheme.downcase}://#{u.host.downcase}#{(u.scheme.casecmp("http").zero? && u.port != 80) || (u.scheme.casecmp("https").zero? && u.port != 443) ? ":#{u.port}" : ""}#{u.path && u.path != "" ? u.path : "/"}" - end - - # See 9.1.1. in specs Normalize Request Parameters - def normalized_parameters - normalize(parameters_for_signature) - end - - def sign(options = {}) - OAuth::Signature.sign(self, options) - end - - def sign!(options = {}) - parameters["oauth_signature"] = sign(options) - @signed = true - signature - end - - # See 9.1 in specs - def signature_base_string - base = [method, normalized_uri, normalized_parameters] - base.map { |v| escape(v) }.join("&") - end - - # Has this request been signed yet? - def signed? - @signed - end - - # URI, including OAuth parameters - def signed_uri(with_oauth: true) - if signed? - params = if with_oauth - parameters - else - non_oauth_parameters - end - - [uri, normalize(params)].join("?") - else - warn "This request has not yet been signed!" - end - end - - # Authorization header for OAuth - def oauth_header(options = {}) - 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? - else - request.query_string.match(/\A\s*\z/) - end - end - - protected - - def header_params - %w[X-HTTP_AUTHORIZATION Authorization HTTP_AUTHORIZATION].each do |header| - next unless request.env.include?(header) - - header = request.env[header] - next unless header[0, 6] == "OAuth " - - # parse the header into a Hash - oauth_params = OAuth::Helper.parse_header(header) - - # remove non-OAuth parameters - oauth_params.select! { |k, _v| k =~ /^oauth_/ } - - return oauth_params - end - - {} - end - end - end -end diff --git a/lib/oauth/request_proxy/curb_request.rb b/lib/oauth/request_proxy/curb_request.rb deleted file mode 100644 index e1999ea1..00000000 --- a/lib/oauth/request_proxy/curb_request.rb +++ /dev/null @@ -1,61 +0,0 @@ -# frozen_string_literal: true - -require "oauth/request_proxy/base" -require "curb" -require "uri" -require "cgi" - -module OAuth - module RequestProxy - module Curl - class Easy < OAuth::RequestProxy::Base - # Proxy for signing Curl::Easy requests - # Usage example: - # oauth_params = {:consumer => oauth_consumer, :token => access_token} - # req = Curl::Easy.new(uri) - # oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri)) - # req.headers.merge!({"Authorization" => oauth_helper.header}) - # req.http_get - # response = req.body_str - proxies ::Curl::Easy - - def method - nil - end - - def uri - options[:uri].to_s - end - - def parameters - if options[:clobber_request] - options[:parameters] - else - post_parameters.merge(query_parameters).merge(options[:parameters] || {}) - end - end - - private - - def query_parameters - query = URI.parse(request.url).query - (query ? CGI.parse(query) : {}) - end - - 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") - - request.post_body.split("&").each do |str| - param = str.split("=") - post_body[param[0]] = param[1] - end - end - post_body - end - end - end - end -end diff --git a/lib/oauth/request_proxy/em_http_request.rb b/lib/oauth/request_proxy/em_http_request.rb deleted file mode 100644 index 4ed830d9..00000000 --- a/lib/oauth/request_proxy/em_http_request.rb +++ /dev/null @@ -1,76 +0,0 @@ -# frozen_string_literal: true - -require "oauth/request_proxy/base" -# em-http also uses adddressable so there is no need to require uri. -require "em-http" -require "cgi" - -module OAuth - module RequestProxy - module EventMachine - class HttpRequest < OAuth::RequestProxy::Base - # A Proxy for use when you need to sign EventMachine::HttpClient instances. - # It needs to be called once the client is construct but before data is sent. - # Also see oauth/client/em-http - proxies ::EventMachine::HttpClient - - # Request in this con - - def method - request.req[:method] - end - - def uri - request.conn.normalize.to_s - end - - def parameters - if options[:clobber_request] - options[:parameters] - else - all_parameters - end - end - - protected - - def all_parameters - merged_parameters({}, post_parameters, query_parameters, options[:parameters]) - end - - def query_parameters - quer = request.req[:query] - hash_quer = if quer.respond_to?(:merge) - quer - else - CGI.parse(quer.to_s) - end - CGI.parse(request.conn.query.to_s).merge(hash_quer) - end - - def post_parameters - headers = request.req[:head] || {} - form_encoded = headers["Content-Type"].to_s.downcase.start_with?("application/x-www-form-urlencoded") - if %w[POST PUT].include?(method) && form_encoded - CGI.parse(request.normalize_body(request.req[:body]).to_s) - else - {} - end - end - - def merged_parameters(params, *extra_params) - extra_params.compact.each do |params_pairs| - params_pairs.each_pair do |key, value| - if params.key?(key) - params[key.to_s] += value - else - params[key.to_s] = [value].flatten - end - end - end - params - end - end - end - end -end diff --git a/lib/oauth/request_proxy/jabber_request.rb b/lib/oauth/request_proxy/jabber_request.rb deleted file mode 100644 index 7f875b9b..00000000 --- a/lib/oauth/request_proxy/jabber_request.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -require "xmpp4r" -require "oauth/request_proxy/base" - -module OAuth - module RequestProxy - class JabberRequest < OAuth::RequestProxy::Base - proxies ::Jabber::Iq - proxies ::Jabber::Presence - proxies ::Jabber::Message - - def parameters - return @params if @params - - @params = {} - - oauth = @request.get_elements("//oauth").first - return @params unless oauth - - %w[ oauth_token oauth_consumer_key oauth_signature_method oauth_signature - oauth_timestamp oauth_nonce oauth_version ].each do |param| - next unless (element = oauth.first_element(param)) - - @params[param] = element.text - end - - @params - end - - def method - @request.name - end - - def uri - [@request.from.strip.to_s, @request.to.strip.to_s].join("&") - end - - def normalized_uri - uri - end - end - end -end diff --git a/lib/oauth/request_proxy/mock_request.rb b/lib/oauth/request_proxy/mock_request.rb deleted file mode 100644 index 33d9a265..00000000 --- a/lib/oauth/request_proxy/mock_request.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -require "oauth/request_proxy/base" - -module OAuth - module RequestProxy - # RequestProxy for Hashes to facilitate simpler signature creation. - # Usage: - # request = OAuth::RequestProxy.proxy \ - # "method" => "iq", - # "uri" => [from, to] * "&", - # "parameters" => { - # "oauth_consumer_key" => oauth_consumer_key, - # "oauth_token" => oauth_token, - # "oauth_signature_method" => "HMAC-SHA1" - # } - # - # signature = OAuth::Signature.sign \ - # request, - # :consumer_secret => oauth_consumer_secret, - # :token_secret => oauth_token_secret, - class MockRequest < OAuth::RequestProxy::Base - proxies ::Hash - - def parameters - @request["parameters"] - end - - def method - @request["method"] - end - - def normalized_uri - super - rescue StandardError - # if this is a non-standard URI, it may not parse properly - # in that case, assume that it's already been normalized - uri - end - - def uri - @request["uri"] - end - end - end -end diff --git a/lib/oauth/request_proxy/net_http.rb b/lib/oauth/request_proxy/net_http.rb deleted file mode 100644 index 849c3fa1..00000000 --- a/lib/oauth/request_proxy/net_http.rb +++ /dev/null @@ -1,80 +0,0 @@ -# frozen_string_literal: true - -require "oauth/request_proxy/base" -require "net/http" -require "uri" -require "cgi" - -module OAuth - module RequestProxy - module Net - module HTTP - class HTTPRequest < OAuth::RequestProxy::Base - proxies ::Net::HTTPGenericRequest - - def method - request.method - end - - def uri - options[:uri].to_s - end - - def parameters - if options[:clobber_request] - options[:parameters] - else - all_parameters - end - end - - def body - request.body - end - - private - - def all_parameters - request_params = CGI.parse(query_string) - # request_params.each{|k,v| request_params[k] = [nil] if v == []} - - options[:parameters]&.each do |k, v| - if request_params.key?(k) && v - request_params[k] << v - else - request_params[k] = [v] - end - end - request_params - end - - def query_string - params = [query_params, auth_header_params] - if (method.to_s.casecmp("POST").zero? || method.to_s.casecmp("PUT").zero?) && form_url_encoded? - params << post_params - end - 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") - end - - def query_params - URI.parse(request.path).query - end - - def post_params - request.body - end - - def auth_header_params - return nil unless request["Authorization"] && request["Authorization"][0, 5] == "OAuth" - - request["Authorization"] - end - end - end - end - end -end diff --git a/lib/oauth/request_proxy/rack_request.rb b/lib/oauth/request_proxy/rack_request.rb deleted file mode 100644 index f006fc4a..00000000 --- a/lib/oauth/request_proxy/rack_request.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -require "oauth/request_proxy/base" -require "uri" -require "rack" - -module OAuth - module RequestProxy - class RackRequest < OAuth::RequestProxy::Base - proxies ::Rack::Request - - def method - request.env["rack.methodoverride.original_method"] || request.request_method - end - - def uri - request.url - end - - def parameters - if options[:clobber_request] - options[:parameters] || {} - else - params = request_params.merge(query_params).merge(header_params) - params.merge(options[:parameters] || {}) - end - end - - def signature - parameters["oauth_signature"] - end - - protected - - def query_params - request.GET - end - - def request_params - if request.content_type && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded") - request.POST - else - {} - end - end - end - end -end diff --git a/lib/oauth/request_proxy/rest_client_request.rb b/lib/oauth/request_proxy/rest_client_request.rb deleted file mode 100644 index 42ef8ae2..00000000 --- a/lib/oauth/request_proxy/rest_client_request.rb +++ /dev/null @@ -1,66 +0,0 @@ -# frozen_string_literal: true - -require "oauth/request_proxy/base" -require "rest-client" -require "uri" -require "cgi" - -module OAuth - module RequestProxy - module RestClient - class Request < OAuth::RequestProxy::Base - proxies ::RestClient::Request - - def method - request.method.to_s.upcase - end - - def uri - request.url - end - - def parameters - if options[:clobber_request] - options[:parameters] || {} - else - post_parameters.merge(query_params).merge(options[:parameters] || {}) - end - end - - protected - - def query_params - query = URI.parse(request.url).query - query ? CGI.parse(query) : {} - end - - def request_params; end - - def post_parameters - # Post params are only used if posting form data - is_form_data = request.payload && request.payload.headers["Content-Type"] == "application/x-www-form-urlencoded" - if is_form_data && (method == "POST" || method == "PUT") - OAuth::Helper.stringify_keys(query_string_to_hash(request.payload.to_s) || {}) - else - {} - end - end - - private - - def query_string_to_hash(query) - query.split("&").inject({}) do |result, q| - k, v = q.split("=") - if !v.nil? - result.merge({ k => v }) - elsif !result.key?(k) - result.merge({ k => true }) - else - result - end - end - end - end - end - end -end diff --git a/lib/oauth/request_proxy/typhoeus_request.rb b/lib/oauth/request_proxy/typhoeus_request.rb deleted file mode 100644 index 10add744..00000000 --- a/lib/oauth/request_proxy/typhoeus_request.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: true - -require "oauth/request_proxy/base" -require "typhoeus" -require "typhoeus/request" -require "uri" -require "cgi" - -module OAuth - module RequestProxy - module Typhoeus - class Request < OAuth::RequestProxy::Base - # Proxy for signing Typhoeus::Request requests - # Usage example: - # oauth_params = {:consumer => oauth_consumer, :token => access_token} - # req = Typhoeus::Request.new(uri, options) - # oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri)) - # req.options[:headers].merge!({"Authorization" => oauth_helper.header}) - # hydra = Typhoeus::Hydra.new() - # hydra.queue(req) - # hydra.run - # response = req.response - proxies ::Typhoeus::Request - - def method - request_method = request.options[:method].to_s.upcase - request_method.empty? ? "GET" : request_method - end - - def uri - options[:uri].to_s - end - - def parameters - if options[:clobber_request] - options[:parameters] - else - post_parameters.merge(query_parameters).merge(options[:parameters] || {}) - end - end - - private - - def query_parameters - query = URI.parse(request.url).query - query ? CGI.parse(query) : {} - end - - def post_parameters - # Post params are only used if posting form data - if method == "POST" - OAuth::Helper.stringify_keys(request.options[:params] || {}) - else - {} - end - end - end - end - end -end diff --git a/lib/oauth/server.rb b/lib/oauth/server.rb deleted file mode 100644 index 033b978c..00000000 --- a/lib/oauth/server.rb +++ /dev/null @@ -1,68 +0,0 @@ -# frozen_string_literal: true - -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 - class Server - include OAuth::Helper - attr_accessor :base_url - - @@server_paths = { - request_token_path: "/oauth/request_token", - authorize_path: "/oauth/authorize", - access_token_path: "/oauth/access_token" - } - - # Create a new server instance - def initialize(base_url, paths = {}) - @base_url = base_url - @paths = @@server_paths.merge(paths) - end - - def generate_credentials - [generate_key(16), generate_key] - end - - def generate_consumer_credentials(_params = {}) - Consumer.new(*generate_credentials) - end - - # mainly for testing purposes - def create_consumer - creds = generate_credentials - Consumer.new(creds[0], creds[1], - { - site: base_url, - request_token_path: request_token_path, - authorize_path: authorize_path, - access_token_path: access_token_path - }) - end - - def request_token_path - @paths[:request_token_path] - end - - def request_token_url - base_url + request_token_path - end - - def authorize_path - @paths[:authorize_path] - end - - def authorize_url - base_url + authorize_path - end - - def access_token_path - @paths[:access_token_path] - end - - def access_token_url - base_url + access_token_path - end - end -end diff --git a/lib/oauth/signature.rb b/lib/oauth/signature.rb deleted file mode 100644 index a8e37f06..00000000 --- a/lib/oauth/signature.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -module OAuth - module Signature - # Returns a list of available signature methods - def self.available_methods - @available_methods ||= {} - end - - # Build a signature from a +request+. - # - # Raises UnknownSignatureMethod exception if the signature method is unknown. - def self.build(request, options = {}, &block) - request = OAuth::RequestProxy.proxy(request, options) - klass = available_methods[ - (request.signature_method || - ((c = request.options[:consumer]) && c.options[:signature_method]) || - "").downcase] - raise UnknownSignatureMethod, request.signature_method unless klass - - klass.new(request, options, &block) - end - - # Sign a +request+ - def self.sign(request, options = {}, &block) - build(request, options, &block).signature - end - - # Verify the signature of +request+ - def self.verify(request, options = {}, &block) - build(request, options, &block).verify - end - - # Create the signature base string for +request+. This string is the normalized parameter information. - # - # See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1] - def self.signature_base_string(request, options = {}, &block) - build(request, options, &block).signature_base_string - end - - # Create the body hash for a request - def self.body_hash(request, options = {}, &block) - build(request, options, &block).body_hash - end - - class UnknownSignatureMethod < RuntimeError; end - end -end diff --git a/lib/oauth/signature/base.rb b/lib/oauth/signature/base.rb deleted file mode 100644 index a0f97f3e..00000000 --- a/lib/oauth/signature/base.rb +++ /dev/null @@ -1,103 +0,0 @@ -# frozen_string_literal: true - -require "oauth/signature" -require "oauth/helper" -require "oauth/request_proxy/base" -require "base64" - -module OAuth - module Signature - class Base - include OAuth::Helper - - attr_accessor :options - attr_reader :token_secret, :consumer_secret, :request - - def self.implements(signature_method = nil) - return @implements if signature_method.nil? - - @implements = signature_method - OAuth::Signature.available_methods[@implements] = self - end - - def initialize(request, options = {}, &block) - raise TypeError unless request.is_a?(OAuth::RequestProxy::Base) - - @request = request - @options = options - - ## consumer secret was determined beforehand - - @consumer_secret = options[:consumer].secret if options[:consumer] - - # presence of :consumer_secret option will override any Consumer that's provided - @consumer_secret = options[:consumer_secret] if options[:consumer_secret] - - ## token secret was determined beforehand - - @token_secret = options[:token].secret if options[:token] - - # presence of :token_secret option will override any Token that's provided - @token_secret = options[:token_secret] if options[:token_secret] - - # override secrets based on the values returned from the block (if any) - if block - # consumer secret and token secret need to be looked up based on pieces of the request - secrets = yield block.arity == 1 ? request : [token, consumer_key, nonce, request.timestamp] - if secrets.is_a?(Array) && secrets.size == 2 - @token_secret = secrets[0] - @consumer_secret = secrets[1] - end - end - end - - def signature - Base64.encode64(digest).chomp.delete("\n") - end - - def ==(other) - check = signature.bytesize ^ other.bytesize - signature.bytes.zip(other.bytes) { |x, y| check |= x ^ y.to_i } - check.zero? - end - - def verify - self == request.signature - end - - def signature_base_string - request.signature_base_string - end - - def body_hash - raise_instantiation_error - end - - private - - def token - request.token - end - - def consumer_key - request.consumer_key - end - - def nonce - request.nonce - end - - def secret - "#{escape(consumer_secret)}&#{escape(token_secret)}" - end - - def digest - raise_instantiation_error - end - - def raise_instantiation_error - raise NotImplementedError, "Cannot instantiate #{self.class.name} class directly." - end - end - end -end diff --git a/lib/oauth/signature/hmac/sha1.rb b/lib/oauth/signature/hmac/sha1.rb deleted file mode 100644 index 79ab8ffd..00000000 --- a/lib/oauth/signature/hmac/sha1.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require "oauth/signature/base" - -module OAuth - module Signature - module HMAC - class SHA1 < OAuth::Signature::Base - implements "hmac-sha1" - - def body_hash - Base64.encode64(OpenSSL::Digest.digest("SHA1", request.body || "")).chomp.delete("\n") - end - - private - - def digest - OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha1"), secret, signature_base_string) - end - end - end - end -end diff --git a/lib/oauth/signature/hmac/sha256.rb b/lib/oauth/signature/hmac/sha256.rb deleted file mode 100644 index c7b3738c..00000000 --- a/lib/oauth/signature/hmac/sha256.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require "oauth/signature/base" - -module OAuth - module Signature - module HMAC - class SHA256 < OAuth::Signature::Base - implements "hmac-sha256" - - def body_hash - Base64.encode64(OpenSSL::Digest.digest("SHA256", request.body || "")).chomp.delete("\n") - end - - private - - def digest - OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha256"), secret, signature_base_string) - end - end - end - end -end diff --git a/lib/oauth/signature/plaintext.rb b/lib/oauth/signature/plaintext.rb deleted file mode 100644 index 87623a22..00000000 --- a/lib/oauth/signature/plaintext.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -require "oauth/signature/base" - -module OAuth - module Signature - class PLAINTEXT < Base - implements "plaintext" - - def signature - signature_base_string - end - - def ==(other) - signature.to_s == other.to_s - end - - def signature_base_string - secret - end - - def body_hash - nil - end - end - end -end diff --git a/lib/oauth/signature/rsa/sha1.rb b/lib/oauth/signature/rsa/sha1.rb deleted file mode 100644 index 01cd1bc7..00000000 --- a/lib/oauth/signature/rsa/sha1.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -require "oauth/signature/base" - -module OAuth - module Signature - module RSA - class SHA1 < OAuth::Signature::Base - implements "rsa-sha1" - - def ==(other) - public_key.verify(OpenSSL::Digest.new("SHA1"), - Base64.decode64(other.is_a?(Array) ? other.first : other), signature_base_string) - end - - def public_key - case consumer_secret - when String - decode_public_key - when OpenSSL::X509::Certificate - consumer_secret.public_key - else - consumer_secret - end - end - - def body_hash - Base64.encode64(OpenSSL::Digest.digest("SHA1", request.body || "")).chomp.delete("\n") - end - - private - - def decode_public_key - case consumer_secret - when /-----BEGIN CERTIFICATE-----/ - OpenSSL::X509::Certificate.new(consumer_secret).public_key - else - OpenSSL::PKey::RSA.new(consumer_secret) - end - end - - def digest - private_key = OpenSSL::PKey::RSA.new( - if options[:private_key_file] - File.read(options[:private_key_file]) - elsif options[:private_key] - options[:private_key] - else - consumer_secret - end - ) - - private_key.sign(OpenSSL::Digest.new("SHA1"), signature_base_string) - end - end - end - end -end diff --git a/lib/oauth/token.rb b/lib/oauth/token.rb deleted file mode 100644 index 5f05aab3..00000000 --- a/lib/oauth/token.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -# 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" diff --git a/lib/oauth/tokens/access_token.rb b/lib/oauth/tokens/access_token.rb deleted file mode 100644 index 9b89833b..00000000 --- a/lib/oauth/tokens/access_token.rb +++ /dev/null @@ -1,85 +0,0 @@ -# frozen_string_literal: true - -module OAuth - # The Access Token is used for the actual "real" web service calls that you perform against the server - class AccessToken < ConsumerToken - # The less intrusive way. Otherwise, if we are to do it correctly inside consumer, - # we need to restructure and touch more methods: request(), sign!(), etc. - def request(http_method, path, *arguments) - request_uri = URI.parse(path) - site_uri = consumer.uri - is_service_uri_different = (request_uri.absolute? && request_uri != site_uri) - begin - consumer.uri(request_uri) if is_service_uri_different - @response = super(http_method, path, *arguments) - ensure - # NOTE: reset for wholesomeness? meaning that we admit only AccessToken service calls may use different URIs? - # so reset in case consumer is still used for other token-management tasks subsequently? - consumer.uri(site_uri) if is_service_uri_different - end - @response - end - - # Make a regular GET request using AccessToken - # - # @response = @token.get('/people') - # @response = @token.get('/people', { 'Accept'=>'application/xml' }) - # - def get(path, headers = {}) - request(:get, path, headers) - end - - # Make a regular HEAD request using AccessToken - # - # @response = @token.head('/people') - # - def head(path, headers = {}) - request(:head, path, headers) - end - - # Make a regular POST request using AccessToken - # - # @response = @token.post('/people') - # @response = @token.post('/people', { :name => 'Bob', :email => 'bob@mailinator.com' }) - # @response = @token.post('/people', { :name => 'Bob', :email => 'bob@mailinator.com' }, { 'Accept' => 'application/xml' }) - # @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 = {}) - request(:post, path, body, headers) - end - - # Make a regular PUT request using AccessToken - # - # @response = @token.put('/people/123') - # @response = @token.put('/people/123', { :name => 'Bob', :email => 'bob@mailinator.com' }) - # @response = @token.put('/people/123', { :name => 'Bob', :email => 'bob@mailinator.com' }, { 'Accept' => 'application/xml' }) - # @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 = {}) - request(:put, path, body, headers) - end - - # Make a regular PATCH request using AccessToken - # - # @response = @token.patch('/people/123') - # @response = @token.patch('/people/123', { :name => 'Bob', :email => 'bob@mailinator.com' }) - # @response = @token.patch('/people/123', { :name => 'Bob', :email => 'bob@mailinator.com' }, { 'Accept' => 'application/xml' }) - # @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 = {}) - request(:patch, path, body, headers) - end - - # Make a regular DELETE request using AccessToken - # - # @response = @token.delete('/people/123') - # @response = @token.delete('/people/123', { 'Accept' => 'application/xml' }) - # - def delete(path, headers = {}) - request(:delete, path, headers) - end - end -end diff --git a/lib/oauth/tokens/consumer_token.rb b/lib/oauth/tokens/consumer_token.rb deleted file mode 100644 index 012faa03..00000000 --- a/lib/oauth/tokens/consumer_token.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -module OAuth - # Superclass for tokens used by OAuth Clients - class ConsumerToken < Token - attr_accessor :consumer, :params - attr_reader :response - - def self.from_hash(consumer, hash) - token = new(consumer, hash[:oauth_token], hash[:oauth_token_secret]) - token.params = hash - token - end - - def initialize(consumer, token = "", secret = "") - super(token, secret) - @consumer = consumer - @params = {} - end - - # Make a signed request using given http_method to the path - # - # @token.request(:get, '/people') - # @token.request(:post, '/people', @person.to_xml, { 'Content-Type' => 'application/xml' }) - # - def request(http_method, path, *arguments) - @response = consumer.request(http_method, path, self, {}, *arguments) - end - - # Sign a request generated elsewhere using Net:HTTP::Post.new or friends - def sign!(request, options = {}) - consumer.sign!(request, self, options) - end - end -end diff --git a/lib/oauth/tokens/request_token.rb b/lib/oauth/tokens/request_token.rb deleted file mode 100644 index c35aca80..00000000 --- a/lib/oauth/tokens/request_token.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -module OAuth - # The RequestToken is used for the initial Request. - # This is normally created by the Consumer object. - class RequestToken < ConsumerToken - # Generate an authorization URL for user authorization - def authorize_url(params = nil) - return nil if token.nil? - - params = (params || {}).merge(oauth_token: token) - build_url(consumer.authorize_url, params) - end - - def authenticate_url(params = nil) - return nil if token.nil? - - params = (params || {}).merge(oauth_token: token) - build_url(consumer.authenticate_url, params) - end - - def callback_confirmed? - params[:oauth_callback_confirmed] == "true" - end - - # exchange for AccessToken on server - def get_access_token(options = {}, *arguments) - response = consumer.token_request(consumer.http_method, - (consumer.access_token_url? ? consumer.access_token_url : consumer.access_token_path), self, options, *arguments) - OAuth::AccessToken.from_hash(consumer, response) - end - - protected - - # construct an authorization or authentication url - def build_url(base_url, params) - uri = URI.parse(base_url.to_s) - queries = {} - queries = URI.decode_www_form(uri.query).to_h if uri.query - # TODO: doesn't handle array values correctly - queries.merge!(params) if params - uri.query = URI.encode_www_form(queries) unless queries.empty? - uri.to_s - end - end -end diff --git a/lib/oauth/tokens/server_token.rb b/lib/oauth/tokens/server_token.rb deleted file mode 100644 index d8c306e6..00000000 --- a/lib/oauth/tokens/server_token.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -module OAuth - # Used on the server for generating tokens - class ServerToken < Token - def initialize - super(generate_key(16), generate_key) - end - end -end diff --git a/lib/oauth/tokens/token.rb b/lib/oauth/tokens/token.rb deleted file mode 100644 index bb0ffca7..00000000 --- a/lib/oauth/tokens/token.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -module OAuth - # Superclass for the various tokens used by OAuth - class Token - include OAuth::Helper - - attr_accessor :token, :secret - - def initialize(token, secret) - @token = token - @secret = secret - end - - def to_query - "oauth_token=#{escape(token)}&oauth_token_secret=#{escape(secret)}" - end - end -end diff --git a/lib/oauth/version.rb b/lib/oauth/version.rb deleted file mode 100644 index 22957622..00000000 --- a/lib/oauth/version.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -module OAuth - module Version - VERSION = "1.1.0" - end -end diff --git a/oauth.gemspec b/oauth.gemspec deleted file mode 100644 index 4956ca39..00000000 --- a/oauth.gemspec +++ /dev/null @@ -1,74 +0,0 @@ -# frozen_string_literal: true - -require_relative "lib/oauth/version" - -Gem::Specification.new do |spec| - # "oauth-tty" was extracted from this gem with release 1.1 of this gem - # It is now a dependency for backward compatibility. - # The dependency will be removed with release 2.0, by April 2023. - spec.add_dependency("oauth-tty", ["~> 1.0", ">= 1.0.1"]) - spec.add_dependency("snaky_hash", "~> 2.0") - spec.add_dependency("version_gem", "~> 1.1") - - spec.name = "oauth" - spec.version = OAuth::Version::VERSION - spec.license = "MIT" - - spec.authors = ["Pelle Braendgaard", "Blaine Cook", "Larry Halff", "Jesse Clark", "Jon Crosby", - "Seth Fitzsimmons", "Matt Sanford", "Aaron Quint", "Peter Boling"] - spec.email = "oauth-ruby@googlegroups.com" - spec.summary = "OAuth Core Ruby implementation" - - spec.homepage = "https://github.com/oauth-xx/oauth-ruby" - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "#{spec.homepage}/tree/v#{spec.version}" - spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md" - spec.metadata["bug_tracker_uri"] = "#{spec.homepage}/issues" - spec.metadata["documentation_uri"] = "https://www.rubydoc.info/gems/#{spec.name}/#{spec.version}" - spec.metadata["wiki_uri"] = "#{spec.homepage}/wiki" - spec.metadata["rubygems_mfa_required"] = "true" - - spec.files = Dir.glob("lib/**/*.rb") + ["LICENSE", "README.md", "CHANGELOG.md", "CODE_OF_CONDUCT.md", "SECURITY.md", - "CONTRIBUTING.md"] - spec.extra_rdoc_files = ["TODO"] - - # This gem will work with Ruby 2.7 or greater... - spec.required_ruby_version = ">= 2.7" - spec.post_install_message = " -You have installed oauth version #{OAuth::Version::VERSION}, congratulations! - -Non-commercial support for the 1.x series will end by April, 2025. Please make a plan to upgrade to the next version prior to that date. -The only breaking change will be dropped support for Ruby 2.7 and any other versions which will also have reached EOL by then. - -Please see: -• #{spec.homepage}/blob/main/SECURITY.md - -Note also that I am, and this project is, in the process of leaving Github. -I wrote about some of the reasons here: -• https://dev.to/galtzo/im-leaving-github-50ba - -If you are a human, please consider a donation as I move toward supporting myself with Open Source work: -• https://liberapay.com/pboling -• https://ko-fi.com/pboling -• https://patreon.com/galtzo - -If you are a corporation, please consider supporting this project, and open source work generally, with a TideLift subscription. -• https://tidelift.com/funding/github/rubygems/oauth -• Or hire me. I am looking for a job! - -Please report issues, and support the project! - -Thanks, |7eter l-|. l3oling -" - spec.add_development_dependency("em-http-request", "~> 1.1.7") - spec.add_development_dependency("iconv") - spec.add_development_dependency("minitest", "~> 5.15.0") - spec.add_development_dependency("mocha") - spec.add_development_dependency("rack", "~> 2.0") - spec.add_development_dependency("rack-test") - spec.add_development_dependency("rake", "~> 13.0") - spec.add_development_dependency("rest-client") - spec.add_development_dependency("rubocop-lts", "~> 18.0") - spec.add_development_dependency("typhoeus", ">= 0.1.13") - spec.add_development_dependency("webmock", "<= 3.19.0") -end diff --git a/test/cases/spec/1_0-final/construct_request_url_test.rb b/test/cases/spec/1_0-final/construct_request_url_test.rb deleted file mode 100644 index cb15b485..00000000 --- a/test/cases/spec/1_0-final/construct_request_url_test.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: true - -require_relative "../../../test_helper" - -# See http://oauth.net/core/1.0/#anchor14 -# -# 9.1.2. Construct Request URL -# -# The Signature Base String includes the request absolute URL, tying the signature to a specific endpoint. The URL used in the Signature Base String MUST include the scheme, authority, and path, and MUST exclude the query and fragment as defined by [RFC3986] section 3. -# -# If the absolute request URL is not available to the Service Provider (it is always available to the Consumer), it can be constructed by combining the scheme being used, the HTTP Host header, and the relative HTTP request URL. If the Host header is not available, the Service Provider SHOULD use the host name communicated to the Consumer in the documentation or other means. -# -# The Service Provider SHOULD document the form of URL used in the Signature Base String to avoid ambiguity due to URL normalization. Unless specified, URL scheme and authority MUST be lowercase and include the port number; http default port 80 and https default port 443 MUST be excluded. -# -# For example, the request: -# -# HTTP://Example.com:80/resource?id=123 -# Is included in the Signature Base String as: -# -# http://example.com/resource - -class ConstructRequestUrlTest < OAuthCase - def test_from_spec - assert_request_url("http://example.com/resource", "HTTP://Example.com:80/resource?id=123") - end - - def test_simple_url_with_ending_slash - assert_request_url("http://example.com/", "http://example.com/") - end - - def test_simple_url_without_ending_slash - assert_request_url("http://example.com/", "http://example.com") - end - - def test_of_normalized_http - assert_request_url("http://example.com/resource", "http://example.com/resource") - end - - def test_of_https - assert_request_url("https://example.com/resource", "HTTPS://Example.com:443/resource?id=123") - end - - def test_of_normalized_https - assert_request_url("https://example.com/resource", "https://example.com/resource") - end - - def test_of_http_with_non_standard_port - assert_request_url("http://example.com:8080/resource", "http://example.com:8080/resource") - end - - def test_of_https_with_non_standard_port - assert_request_url("https://example.com:8080/resource", "https://example.com:8080/resource") - end - - protected - - def assert_request_url(expected, given, message = nil) - assert_equal expected, request({}, "GET", given).normalized_uri, message - end -end diff --git a/test/cases/spec/1_0-final/normalize_request_parameters_test.rb b/test/cases/spec/1_0-final/normalize_request_parameters_test.rb deleted file mode 100644 index e104fa04..00000000 --- a/test/cases/spec/1_0-final/normalize_request_parameters_test.rb +++ /dev/null @@ -1,86 +0,0 @@ -# frozen_string_literal: true - -require_relative "../../../test_helper" - -# See http://oauth.net/core/1.0/#anchor14 -# -# 9.1.1. Normalize Request Parameters -# -# The request parameters are collected, sorted and concatenated into a normalized string: -# -# Parameters in the OAuth HTTP Authorization header excluding the realm parameter. -# Parameters in the HTTP POST request body (with a content-type of application/x-www-form-urlencoded). -# HTTP GET parameters added to the URLs in the query part (as defined by [RFC3986] section 3). -# The oauth_signature parameter MUST be excluded. -# -# The parameters are normalized into a single string as follows: -# -# Parameters are sorted by name, using lexicographical byte value ordering. -# If two or more parameters share the same name, they are sorted by their value. For example: -# -# a=1, c=hi%20there, f=25, f=50, f=a, z=p, z=t -# Parameters are concatenated in their sorted order into a single string. For each parameter, -# the name is separated from the corresponding value by an ‘=’ character (ASCII code 61), even -# if the value is empty. Each name-value pair is separated by an ‘&’ character (ASCII code 38). For example: -# a=1&c=hi%20there&f=25&f=50&f=a&z=p&z=t -# - -class NormalizeRequestParametersTest < OAuthCase - def test_parameters_for_signature - params = { "a" => 1, "c" => "hi there", "f" => "a", "z" => "t" } - assert_equal params, request(params).parameters_for_signature - end - - 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 - 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" => %w[25 50 a], "z" => %w[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" => %w[a 70 5], "z" => %w[p t] } - end - - def test_empty - assert_normalized "", {} - end - - # These are from the wiki http://wiki.oauth.net/TestCases - # in the section Normalize Request Parameters - # Parameters have already been x-www-form-urlencoded (i.e. + = ) - def test_wiki1 - assert_normalized "name=", { "name" => nil } - end - - def test_wiki2 - assert_normalized "a=b", { "a" => "b" } - end - - def test_wiki3 - 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"] } - end - - def test_wiki5 - assert_normalized "x=a&x%21y=a", { "x!y" => "a", "x" => "a" } - end - - protected - - def assert_normalized(expected, params, message = nil) - assert_equal expected, normalize_request_parameters(params), message - end - - def normalize_request_parameters(params = {}) - request(params).normalized_parameters - end -end diff --git a/test/cases/spec/1_0-final/parameter_encodings_test.rb b/test/cases/spec/1_0-final/parameter_encodings_test.rb deleted file mode 100644 index c57cafc2..00000000 --- a/test/cases/spec/1_0-final/parameter_encodings_test.rb +++ /dev/null @@ -1,89 +0,0 @@ -# frozen_string_literal: true - -require_relative "../../../test_helper" - -# See http://oauth.net/core/1.0/#encoding_parameters -# -# 5.1. Parameter Encoding -# -# All parameter names and values are escaped using the [RFC3986] percent-encoding (%xx) mechanism. -# Characters not in the unreserved character set ([RFC3986] section 2.3) MUST be encoded. Characters -# in the unreserved character set MUST NOT be encoded. Hexadecimal characters in encodings MUST be -# upper case. Text names and values MUST be encoded as UTF-8 octets before percent-encoding them per [RFC3629]. -# -# unreserved = ALPHA, DIGIT, '-', '.', '_', '~' -# - -class ParameterEncodingTest < OAuthCase - def test_encodings_alpha_num - assert_encoding "abcABC123", "abcABC123" - end - - def test_encodings_non_escaped - assert_encoding "-._~", "-._~" - end - - def test_encodings_percent - assert_encoding "%25", "%" - end - - def test_encodings_plus - assert_encoding "%2B", "+" - end - - def test_encodings_space - assert_encoding "%20", " " - end - - def test_encodings_query_param_symbols - assert_encoding "%26%3D%2A", "&=*" - end - - def test_encodings_unicode_lf - assert_encoding "%0A", unicode_to_utf8("U+000A") - end - - def test_encodings_unicode_space - assert_encoding "%20", unicode_to_utf8("U+0020") - end - - def test_encodings_unicode007f - assert_encoding "%7F", unicode_to_utf8("U+007F") - end - - def test_encodings_unicode0080 - assert_encoding "%C2%80", unicode_to_utf8("U+0080") - end - - def test_encoding_unicode2708 - assert_encoding "%E2%9C%88", unicode_to_utf8("U+2708") - end - - def test_encodings_unicode3001 - assert_encoding "%E3%80%81", unicode_to_utf8("U+3001") - end - - protected - - def unicode_to_utf8(unicode) - return unicode if unicode =~ /\A[[:space:]]*\z/m - - str = "" - - # :xdigit: character set (hexadecimal) includes the character set of :digit: (decimal) - unicode.scan(/(U\+(?:[[:xdigit:]]{4,5}|10[[:xdigit:]]{4})|.)/mu) do - c = Regexp.last_match(1) - str += if /^U\+/.match?(c) - [c[2..].hex].pack("U*") - else - c - end - end - - str - end - - def assert_encoding(expected, given, message = nil) - assert_equal expected, OAuth::Helper.escape(given), message - end -end diff --git a/test/cases/spec/1_0-final/signature_base_strings_test.rb b/test/cases/spec/1_0-final/signature_base_strings_test.rb deleted file mode 100644 index b288716a..00000000 --- a/test/cases/spec/1_0-final/signature_base_strings_test.rb +++ /dev/null @@ -1,77 +0,0 @@ -# frozen_string_literal: true - -require_relative "../../../test_helper" - -# See http://oauth.net/core/1.0/#anchor14 -# -# 9.1. Signature Base String -# -# The Signature Base String is a consistent reproducible concatenation of the request elements -# into a single string. The string is used as an input in hashing or signing algorithms. The -# HMAC-SHA1 signature method provides both a standard and an example of using the Signature -# Base String with a signing algorithm to generate signatures. All the request parameters MUST -# be encoded as described in Parameter Encoding prior to constructing the Signature Base String. -# - -class SignatureBaseStringTest < OAuthCase - def test_a51 - 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" - } - 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" - end - - # These are from the wiki http://wiki.oauth.net/TestCases - # in the section Concatenate Test Elements - - def test_wiki_1_simple_with_ending_slash - parameters = { - "n" => "v" - } - sbs = "GET&http%3A%2F%2Fexample.com%2F&n%3Dv" - - assert_signature_base_string sbs, parameters, "GET", "http://example.com/" - end - - def test_wiki_2_simple_without_ending_slash - parameters = { - "n" => "v" - } - sbs = "GET&http%3A%2F%2Fexample.com%2F&n%3Dv" - - 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" - end - - protected - - 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") - request(params, method, uri).signature_base_string - end -end diff --git a/test/keys/rsa.cert b/test/keys/rsa.cert deleted file mode 100644 index f7b5c093..00000000 --- a/test/keys/rsa.cert +++ /dev/null @@ -1,11 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIBpjCCAQ+gAwIBAgIBATANBgkqhkiG9w0BAQUFADAZMRcwFQYDVQQDDA5UZXN0 -IFByaW5jaXBhbDAeFw03MDAxMDEwODAwMDBaFw0zODEyMzEwODAwMDBaMBkxFzAV -BgNVBAMMDlRlc3QgUHJpbmNpcGFsMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB -gQC0YjCwIfYoprq/FQO6lb3asXrxLlJFuCvtinTF5p0GxvQGu5O3gYytUvtC2JlY -zypSRjVxwxrsuRcP3e641SdASwfrmzyvIgP08N4S0IFzEURkV1wp/IpH7kH41Etb -mUmrXSwfNZsnQRE5SYSOhh+LcK2wyQkdgcMv11l4KoBkcwIDAQABMA0GCSqGSIb3 -DQEBBQUAA4GBAGZLPEuJ5SiJ2ryq+CmEGOXfvlTtEL2nuGtr9PewxkgnOjZpUy+d -4TvuXJbNQc8f4AMWL/tO9w0Fk80rWKp9ea8/df4qMq5qlFWlx6yOLQxumNOmECKb -WpkUQDIDJEoFUzKMVuJf4KO/FJ345+BNLGgbJ6WujreoM1X/gYfdnJ/J ------END CERTIFICATE----- \ No newline at end of file diff --git a/test/keys/rsa.pem b/test/keys/rsa.pem deleted file mode 100644 index e0f55425..00000000 --- a/test/keys/rsa.pem +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALRiMLAh9iimur8V -A7qVvdqxevEuUkW4K+2KdMXmnQbG9Aa7k7eBjK1S+0LYmVjPKlJGNXHDGuy5Fw/d -7rjVJ0BLB+ubPK8iA/Tw3hLQgXMRRGRXXCn8ikfuQfjUS1uZSatdLB81mydBETlJ -hI6GH4twrbDJCR2Bwy/XWXgqgGRzAgMBAAECgYBYWVtleUzavkbrPjy0T5FMou8H -X9u2AC2ry8vD/l7cqedtwMPp9k7TubgNFo+NGvKsl2ynyprOZR1xjQ7WgrgVB+mm -uScOM/5HVceFuGRDhYTCObE+y1kxRloNYXnx3ei1zbeYLPCHdhxRYW7T0qcynNmw -rn05/KO2RLjgQNalsQJBANeA3Q4Nugqy4QBUCEC09SqylT2K9FrrItqL2QKc9v0Z -zO2uwllCbg0dwpVuYPYXYvikNHHg+aCWF+VXsb9rpPsCQQDWR9TT4ORdzoj+Nccn -qkMsDmzt0EfNaAOwHOmVJ2RVBspPcxt5iN4HI7HNeG6U5YsFBb+/GZbgfBT3kpNG -WPTpAkBI+gFhjfJvRw38n3g/+UeAkwMI2TJQS4n8+hid0uus3/zOjDySH3XHCUno -cn1xOJAyZODBo47E+67R4jV1/gzbAkEAklJaspRPXP877NssM5nAZMU0/O/NGCZ+ -3jPgDUno6WbJn5cqm8MqWhW1xGkImgRk+fkDBquiq4gPiT898jusgQJAd5Zrr6Q8 -AO/0isr/3aa6O6NLQxISLKcPDk2NOccAfS/xOtfOz4sJYM3+Bs4Io9+dZGSDCA54 -Lw03eHTNQghS0A== ------END PRIVATE KEY----- \ No newline at end of file diff --git a/test/support/minitest_helpers.rb b/test/support/minitest_helpers.rb deleted file mode 100644 index 1bffdad6..00000000 --- a/test/support/minitest_helpers.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -module OAuth - module MinitestHelpers - def assert_matching_headers(expected, actual) - # transform into sorted arrays - auth_intro, auth_params = actual.split(" ", 2) - assert_equal("OAuth", auth_intro) - 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 - - def stub_test_ie - stub_request(:any, - "http://term.ie/oauth/example/request_token.php").to_return(body: "oauth_token=requestkey&oauth_token_secret=requestsecret") - stub_request(:post, - "http://term.ie/oauth/example/access_token.php").to_return(body: "oauth_token=accesskey&oauth_token_secret=accesssecret") - stub_request(:get, %r{http://term\.ie/oauth/example/echo_api\.php\?.+}).to_return(lambda { |request| - { body: request.uri.query } - }) - stub_request(:post, "http://term.ie/oauth/example/echo_api.php").to_return(lambda { |request| - { body: request.body } - }) - end - end -end - -Minitest::Test.include OAuth::MinitestHelpers diff --git a/test/support/oauth_case.rb b/test/support/oauth_case.rb deleted file mode 100644 index 439f6c8b..00000000 --- a/test/support/oauth_case.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -require "oauth/signature" -require "oauth/request_proxy/mock_request" - -class OAuthCase < Minitest::Test - # avoid whining about a lack of tests - def run(*args) - @method_name ||= nil - return if @method_name.to_s == "default_test" - - super - end - - 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 }) - end -end diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index e42a6345..00000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -# ensure test env -ENV["RACK_ENV"] = "test" - -# Third Party Libraries -require "stringio" -require "minitest" -require "mocha/minitest" -require "rack/test" -require "webmock/minitest" - -DEBUG = ENV["DEBUG"] == "true" - -ruby_version = Gem::Version.new(RUBY_VERSION) -minimum_version = ->(version, engine = "ruby") { ruby_version>= Gem::Version.new(version) && RUBY_ENGINE == engine } -actual_version = lambda do |major, minor| - actual = Gem::Version.new(ruby_version) - major == actual.segments[0] && minor == actual.segments[1] && RUBY_ENGINE == "ruby" -end -debugging = minimum_version.call("2.7") && DEBUG -RUN_COVERAGE = minimum_version.call("2.7") && (ENV.fetch("COVER_ALL") { ENV.fetch("CI_CODECOV") { ENV["CI"].nil? } }) -ALL_FORMATTERS = actual_version.call(2, 7) && (ENV.fetch("COVER_ALL") do - ENV.fetch("CI_CODECOV") do - ENV.fetch("CI", nil) - end -end) - -require "byebug" if debugging - -if RUN_COVERAGE - require "simplecov" # Config file `.simplecov` is run immediately when simplecov loads - require "codecov" - require "simplecov-json" - require "simplecov-lcov" - require "simplecov-cobertura" - # This will override the formatter set in .simplecov - if ALL_FORMATTERS - SimpleCov::Formatter::LcovFormatter.config do |c| - c.report_with_single_file = true - c.single_report_path = "coverage/lcov.info" - end - - SimpleCov.formatters = [ - SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::CoberturaFormatter, # XML for Jenkins - SimpleCov::Formatter::LcovFormatter, - SimpleCov::Formatter::JSONFormatter, # For CodeClimate - SimpleCov::Formatter::Codecov # For CodeCov - ] - end -end - -# This gem -require "oauth" - -# Test Support Code -require "support/minitest_helpers" -require "support/oauth_case" - -# Run the tests! -require "minitest/autorun" diff --git a/test/units/access_token_test.rb b/test/units/access_token_test.rb deleted file mode 100644 index 4bf5c42b..00000000 --- a/test/units/access_token_test.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -class AccessTokenTest < Minitest::Test - def setup - @fake_response = { - user_id: 5_734_758_743_895, - oauth_token: "key", - oauth_token_secret: "secret" - } - # setup a fake req. token. mocking Consumer would be more appropriate... - @access_token = OAuth::AccessToken.from_hash( - OAuth::Consumer.new("key", "secret", {}), - @fake_response - ) - end - - def test_provides_response_parameters - assert @access_token - assert_respond_to @access_token, :params - end - - def test_access_token_makes_non_oauth_response_params_available - assert @access_token.params[:user_id] - assert_equal 5_734_758_743_895, @access_token.params[:user_id] - end -end diff --git a/test/units/action_controller_request_proxy_test.rb b/test/units/action_controller_request_proxy_test.rb deleted file mode 100644 index 7957dda7..00000000 --- a/test/units/action_controller_request_proxy_test.rb +++ /dev/null @@ -1,146 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -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 = "/" - - case request_method - when :post - request.env["REQUEST_METHOD"] = "POST" - when :put - request.env["REQUEST_METHOD"] = "PUT" - when :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" - - 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" }) - - expected_parameters = [%w[key value]] - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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" }) - - expected_parameters = [%w[key value]] - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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" }) - - expected_parameters = [%w[key value]] - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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" }) - - expected_parameters = [%w[key value]] - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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" }) - - expected_parameters = [] - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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" }) - - expected_parameters = [%w[key value]] - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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" }) - - expected_parameters = [%w[key value]] - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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" }) - - expected_parameters = [] - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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" }) - - expected_parameters = [%w[key value]] - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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" }) - - expected_parameters = [%w[key value], %w[key2 value2]] - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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" }) - - expected_parameters = [%w[key value], %w[key2 value2]] - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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" }) - - expected_parameters = [%w[key value]] - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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 - ) - 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 - ) - end - - def test_parameter_keys_should_preserve_brackets_from_array - assert_equal( - [["foo[]", "123"], ["foo[]", "456"]], - request_proxy(:post, { foo: [123, 456] }).parameters_for_signature.sort - ) - end -end diff --git a/test/units/action_dispatch_request_proxy_test.rb b/test/units/action_dispatch_request_proxy_test.rb deleted file mode 100644 index 0161481a..00000000 --- a/test/units/action_dispatch_request_proxy_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -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" }) - - 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 - 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 }) - - 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 - 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 }) - - 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 - end -end diff --git a/test/units/cli_test.rb b/test/units/cli_test.rb deleted file mode 100644 index 8ab34962..00000000 --- a/test/units/cli_test.rb +++ /dev/null @@ -1,307 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -require "oauth/cli" - -class CliTest < Minitest::Test - def test_parse_dashed - 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") - end - - def test_parse_default - assert_equal "help", parse("") - assert_equal "help", parse(nil) - - assert_equal "help", parse("NotACommand") - end - - def test_parse_abbr_lower - 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") - end - - def test_parse_full_lower - 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_parse_abbr_upper - 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") - end - - def test_parse_full_upper - 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 - out = run_command - - assert_match(/Usage: /, out) - end - - def test_help - out = run_command(%w[help]) - - assert_match(/Usage: /, out) - end - - def test_version - out = run_command(%w[version]) - - assert_match "OAuth Gem #{OAuth::Version::VERSION}\n", out - end - - def test_query_empty - out = run_command(%w[query]) - - assert_equal help_output, out - end - - def test_sign_empty - out = run_command(%w[sign]) - - assert_equal help_output, out - end - - def test_authorize_empty - out = run_command(%w[authorize]) - - assert_equal help_output, out - end - - def test_query - consumer = Minitest::Mock.new - access_token = MiniTest::Mock.new - response = MiniTest::Mock.new - - 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 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 - access_token - } - - # mock expects: - # method return arguments - #------------------------------------------------------------- - 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::AccessToken.stub(:new, access_token_new) do - OAuth::Consumer.stub(:new, consumer_new) do - out = run_command %w[query - --consumer-key oauth_consumer_key - --consumer-secret oauth_consumer_secret - --token TOKEN - --secret SECRET - --uri http://example.com/oauth/url] - - assert_equal(<<~expected, out) - 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 - !code! !message! - !body! - EXPECTED - end - end - end - end - end - - def test_authorize - access_token = MiniTest::Mock.new - consumer = MiniTest::Mock.new - request_token = MiniTest::Mock.new - - 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 expected_options, options - consumer - } - - # mock expects: - # method return arguments - #---------------------------------------------------------------------- - access_token.expect(:params, {}) - consumer.expect(:get_request_token, request_token, [{ oauth_callback: nil }, {}]) - request_token.expect(:callback_confirmed?, false) - 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::Consumer.stub(:new, consumer_new) do - out = run_command %w[authorize - --consumer-key oauth_consumer_key - --consumer-secret oauth_consumer_secret - --method GET - --uri http://example.com/oauth/url] - - assert_equal(<<~expected, out) - Please visit this url to authorize: - !url1! - Press return to continue... - Response: - EXPECTED - end - end - end - end - - def test_sign - access_token = MiniTest::Mock.new - consumer = MiniTest::Mock.new - request_token = MiniTest::Mock.new - - 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 expected_options, options - consumer - } - - # mock expects: - # method return arguments - #---------------------------------------------------------------------- - access_token.expect(:params, {}) - consumer.expect(:get_request_token, request_token, [{ oauth_callback: nil }, {}]) - request_token.expect(:callback_confirmed?, false) - request_token.expect(:authorize_url, "!url1!") - request_token.expect(:get_access_token, access_token, [{ oauth_verifier: nil }]) - - out = [] - - 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 - --consumer-key oauth_consumer_key - --consumer-secret oauth_consumer_secret - --method GET - --token TOKEN - --secret SECRET - --uri http://example.com/oauth/url - -v] - - out.push run_command %w[sign - --consumer-key oauth_consumer_key - --consumer-secret oauth_consumer_secret - --method GET - --token TOKEN - --secret SECRET - --uri http://example.com/oauth/url] - end - end - end - - assert_equal(<<~expected, out.pop) - MujZyJYT5ix2s388yF8sExvPIgA= - EXPECTED - - assert_equal(<<~expected, out.pop) - OAuth parameters: - 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 - - Method: GET - URI: http://example.com/oauth/url - Normalized params: oauth_consumer_key=oauth_consumer_key&oauth_nonce=GENERATE_KEY&oauth_signature_method=HMAC-SHA1&oauth_timestamp=GENERATE_TIMESTAMP&oauth_token=TOKEN&oauth_version=1.0 - Signature base string: GET&http%3A%2F%2Fexample.com%2Foauth%2Furl&oauth_consumer_key%3Doauth_consumer_key%26oauth_nonce%3DGENERATE_KEY%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3DGENERATE_TIMESTAMP%26oauth_token%3DTOKEN%26oauth_version%3D1.0 - OAuth Request URI: http://example.com/oauth/url?oauth_consumer_key=oauth_consumer_key&oauth_nonce=GENERATE_KEY&oauth_signature=MujZyJYT5ix2s388yF8sExvPIgA%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=GENERATE_TIMESTAMP&oauth_token=TOKEN&oauth_version=1.0 - Request URI: http://example.com/oauth/url? - Authorization header: OAuth 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_signature=\"MujZyJYT5ix2s388yF8sExvPIgA%3D\" - Signature: MujZyJYT5ix2s388yF8sExvPIgA= - Escaped signature: MujZyJYT5ix2s388yF8sExvPIgA%3D - EXPECTED - end - - private - - def run_command(arguments = []) - s = StringIO.new - command = arguments.shift - OAuth::CLI.new(s, StringIO.new, StringIO.new, command, arguments).run - - s.rewind - s.read - end - - def parse(command) - cli = OAuth::CLI.new(StringIO.new, StringIO.new, StringIO.new, command, []) - cli.send(:parse_command, command) - end - - def help_output - <<~expected - Usage: oauth [ARGS] - -B, --body Use the request body for OAuth parameters. - --consumer-key KEY Specifies the consumer key to use. - --consumer-secret SECRET Specifies the consumer secret to use. - -H, --header Use the 'Authorization' header for OAuth parameters (default). - -Q, --query-string Use the query string for OAuth parameters. - -O, --options FILE Read options from a file - - options for signing and querying - --method METHOD Specifies the method (e.g. GET) to use when signing. - --nonce NONCE Specifies the nonce to use. - --parameters PARAMS Specifies the parameters to use when signing. - --signature-method METHOD Specifies the signature method to use; defaults to HMAC-SHA1. - --token TOKEN Specifies the token to use. - --secret SECRET Specifies the token secret to use. - --timestamp TIMESTAMP Specifies the timestamp to use. - --realm REALM Specifies the realm to use. - --uri URI Specifies the URI to use when signing. - --version [VERSION] Specifies the OAuth version to use. - --no-version Omit oauth_version. - --xmpp Generate XMPP stanzas. - -v, --verbose Be verbose. - - options for authorization - --access-token-url URL Specifies the access token URL. - --authorize-url URL Specifies the authorization URL. - --callback-url URL Specifies a callback URL. - --request-token-url URL Specifies the request token URL. - --scope SCOPE Specifies the scope (Google-specific). - EXPECTED - end -end diff --git a/test/units/client_helper_test.rb b/test/units/client_helper_test.rb deleted file mode 100644 index 8cc8a578..00000000 --- a/test/units/client_helper_test.rb +++ /dev/null @@ -1,149 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -require "oauth/client" - -class ClientHelperTest < Minitest::Test - def setup - @consumer = OAuth::Consumer.new( - "consumer_key_86cad9", "5888bf0345e5d237", - { - site: "http://blabla.bla", - proxy: "http://user:password@proxy.bla:8080", - request_token_path: "/oauth/example/request_token.php", - access_token_path: "/oauth/example/access_token.php", - authorize_path: "/oauth/example/authorize.php", - scheme: :header, - http_method: :get - } - ) - end - - 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 - expected = { - "oauth_consumer_key" => "consumer_key_86cad9", - "oauth_signature_method" => "HMAC-SHA1", - "oauth_timestamp" => "0", - "oauth_nonce" => "nonce", - "oauth_version" => "1.0" - } - assert_equal expected, helper.oauth_parameters - end - end - end - - def test_oauth_parameters_allow_empty_params_true - input = true - helper = OAuth::Client::Helper.new(nil, { - consumer: @consumer, - allow_empty_params: input - }) - helper.stub :timestamp, "0" do - helper.stub :nonce, "nonce" do - expected = { - "oauth_body_hash" => nil, - "oauth_callback" => nil, - "oauth_consumer_key" => "consumer_key_86cad9", - "oauth_token" => "", - "oauth_signature_method" => "HMAC-SHA1", - "oauth_timestamp" => "0", - "oauth_nonce" => "nonce", - "oauth_verifier" => nil, - "oauth_version" => "1.0", - "oauth_session_handle" => nil - } - assert_equal expected, helper.oauth_parameters - end - end - end - - def test_oauth_parameters_allow_empty_params_false - input = false - helper = OAuth::Client::Helper.new(nil, { - consumer: @consumer, - allow_empty_params: input - }) - helper.stub :timestamp, "0" do - helper.stub :nonce, "nonce" do - expected = { - "oauth_consumer_key" => "consumer_key_86cad9", - "oauth_signature_method" => "HMAC-SHA1", - "oauth_timestamp" => "0", - "oauth_nonce" => "nonce", - "oauth_version" => "1.0" - } - assert_equal expected, helper.oauth_parameters - end - end - end - - def test_oauth_parameters_allow_empty_params_only_oauth_token_as_string - 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 - expected = { - "oauth_consumer_key" => "consumer_key_86cad9", - "oauth_token" => "", - "oauth_signature_method" => "HMAC-SHA1", - "oauth_timestamp" => "0", - "oauth_nonce" => "nonce", - "oauth_version" => "1.0" - } - assert_equal expected, helper.oauth_parameters - end - end - end - - def test_oauth_parameters_allow_empty_params_only_oauth_token_as_array - 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 - expected = { - "oauth_consumer_key" => "consumer_key_86cad9", - "oauth_token" => "", - "oauth_signature_method" => "HMAC-SHA1", - "oauth_timestamp" => "0", - "oauth_nonce" => "nonce", - "oauth_version" => "1.0" - } - assert_equal expected, helper.oauth_parameters - end - end - end - - def test_oauth_parameters_allow_empty_params_oauth_token_and_oauth_session_handle - input = %w[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 - expected = { - "oauth_consumer_key" => "consumer_key_86cad9", - "oauth_token" => "", - "oauth_signature_method" => "HMAC-SHA1", - "oauth_timestamp" => "0", - "oauth_nonce" => "nonce", - "oauth_version" => "1.0", - "oauth_session_handle" => nil - } - assert_equal expected, helper.oauth_parameters - end - end - end -end diff --git a/test/units/consumer_integration_test.rb b/test/units/consumer_integration_test.rb deleted file mode 100644 index ebc3bb5e..00000000 --- a/test/units/consumer_integration_test.rb +++ /dev/null @@ -1,322 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -class ConsumerIntegrationTest < Minitest::Test - def setup - @consumer = OAuth::Consumer.new( - "consumer_key_86cad9", "5888bf0345e5d237", - { - site: "http://blabla.bla", - proxy: "http://user:password@proxy.bla:8080", - request_token_path: "/oauth/example/request_token.php", - access_token_path: "/oauth/example/access_token.php", - authorize_path: "/oauth/example/authorize.php", - 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" } - @nonce = 225_579_211_881_198_842_005_988_698_334_675_835_446 - @timestamp = "1199645624" - @consumer.http = Net::HTTP.new(@request_uri.host, @request_uri.port) - end - - 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 - end - - def test_that_setting_signature_method_on_consumer_effects_signing - request = Net::HTTP::Get.new(@request_uri.path) - consumer = @consumer.dup - 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"]) - end - - def test_that_setting_signature_method_on_consumer_effects_signature_base_string - # Net::HTTP::Get.new(@request_uri.path) - consumer = @consumer.dup - consumer.options[:signature_method] = "PLAINTEXT" - - request = Net::HTTP::Get.new("/") - signature_base_string = consumer.signature_base_string(request) - - refute_match(/HMAC-SHA1/, signature_base_string) - assert_equal("#{consumer.secret}&", signature_base_string) - end - - def test_that_plaintext_signature_works - # Invalid test because server expects double-escaped signature - - # consumer = OAuth::Consumer.new("key", "secret", - # :site => "http://term.ie", :signature_method => 'PLAINTEXT') - # access_token = OAuth::AccessToken.new(consumer, 'accesskey', 'accesssecret') - # response = access_token.get("/oauth/example/echo_api.php?echo=hello") - - # assert_equal 'echo=hello', response.body - end - - def test_that_signing_auth_headers_on_post_requests_works - request = Net::HTTP::Post.new(@request_uri.path) - request.set_form_data(@request_parameters) - @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 - 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 }) - - 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"] - 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 - end - - def test_using_auth_headers_on_post_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 - end - - def test_signing_post_params_works2 - 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_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"] - end - - def test_step_by_step_token_request - stub_test_ie - - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - site: "http://term.ie", - request_token_path: "/oauth/example/request_token.php", - access_token_path: "/oauth/example/access_token.php", - authorize_path: "/oauth/example/authorize.php", - scheme: :header - } - ) - 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_nil request.body - response = @consumer.http.request(request) - assert_equal "200", response.code - assert_equal "oauth_token=requestkey&oauth_token_secret=requestsecret", response.body - end - - def test_get_token_sequence - stub_test_ie - - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - site: "http://term.ie", - request_token_path: "/oauth/example/request_token.php", - access_token_path: "/oauth/example/access_token.php", - authorize_path: "/oauth/example/authorize.php" - } - ) - assert_equal "http://term.ie/oauth/example/request_token.php", @consumer.request_token_url - assert_equal "http://term.ie/oauth/example/access_token.php", @consumer.access_token_url - - refute_predicate @consumer, :request_token_url?, "Should not use fully qualified request token url" - refute_predicate @consumer, :access_token_url?, "Should not use fully qualified access token url" - refute_predicate @consumer, :authorize_url?, "Should not use fully qualified url" - - @request_token = @consumer.get_request_token - assert @request_token - assert_equal "requestkey", @request_token.token - assert_equal "requestsecret", @request_token.secret - assert_equal "http://term.ie/oauth/example/authorize.php?oauth_token=requestkey", @request_token.authorize_url - - @access_token = @request_token.get_access_token - assert @access_token - assert_equal "accesskey", @access_token.token - assert_equal "accesssecret", @access_token.secret - - @response = @access_token.get("/oauth/example/echo_api.php?ok=hello&test=this") - assert @response - 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" }) - assert @response - assert_equal "200", @response.code - assert_equal("ok=hello&test=this", @response.body) - end - - def test_get_token_sequence_using_fqdn - stub_test_ie - - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - site: "http://term.ie", - request_token_url: "http://term.ie/oauth/example/request_token.php", - access_token_url: "http://term.ie/oauth/example/access_token.php", - authorize_url: "http://term.ie/oauth/example/authorize.php" - } - ) - assert_equal "http://term.ie/oauth/example/request_token.php", @consumer.request_token_url - assert_equal "http://term.ie/oauth/example/access_token.php", @consumer.access_token_url - - assert_predicate @consumer, :request_token_url?, "Should use fully qualified request token url" - assert_predicate @consumer, :access_token_url?, "Should use fully qualified access token url" - assert_predicate @consumer, :authorize_url?, "Should use fully qualified url" - - @request_token = @consumer.get_request_token - assert @request_token - assert_equal "requestkey", @request_token.token - assert_equal "requestsecret", @request_token.secret - assert_equal "http://term.ie/oauth/example/authorize.php?oauth_token=requestkey", @request_token.authorize_url - - @access_token = @request_token.get_access_token - assert @access_token - assert_equal "accesskey", @access_token.token - assert_equal "accesssecret", @access_token.secret - - @response = @access_token.get("/oauth/example/echo_api.php?ok=hello&test=this") - assert @response - 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" }) - assert @response - assert_equal "200", @response.code - assert_equal("ok=hello&test=this", @response.body) - end - - # This test does an actual https request (the result doesn't matter) - # to initialize the same way as get_request_token does. Can be any - # site that supports https. - # - # It also generates "warning: using default DH parameters." which I - # don't know how to get rid of - # def test_serialization_with_https - # consumer = OAuth::Consumer.new('token', 'secret', :site => 'https://plazes.net') - # consumer.http.verify_mode = OpenSSL::SSL::VERIFY_NONE - # consumer.http.get('/') - # - # assert_nothing_raised do - # # Specifically this should not raise TypeError: no marshal_dump - # # is defined for class OpenSSL::SSL::SSLContext - # Marshal.dump(consumer) - # end - # end - # - def test_get_request_token_with_custom_arguments - stub_test_ie - - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - site: "http://term.ie", - request_token_path: "/oauth/example/request_token.php", - access_token_path: "/oauth/example/access_token.php", - authorize_path: "/oauth/example/authorize.php" - } - ) - - @consumer.get_request_token({}, - { scope: "http://www.google.com/calendar/feeds http://picasaweb.google.com/data" }) - - # Because this is a POST request, create_http_request should take the first element of *arguments - # and turn it into URL-encoded data in the body of the POST. - end - - def test_post_with_body_stream - stub_test_ie - - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - site: "http://term.ie", - request_token_path: "/oauth/example/request_token.php", - access_token_path: "/oauth/example/access_token.php", - authorize_path: "/oauth/example/authorize.php" - } - ) - - @request_token = @consumer.get_request_token - @access_token = @request_token.get_access_token - - request_body_string = "Hello, hello, hello" - request_body_stream = StringIO.new(request_body_string) - - @response = @access_token.post("/oauth/example/echo_api.php", request_body_stream) - assert @response - assert_equal "200", @response.code - - request_body_file = File.open(__FILE__) - - @response = @access_token.post("/oauth/example/echo_api.php", request_body_file) - assert @response - assert_equal "200", @response.code - - # unfortunately I don't know of a way to test that the body data was received correctly since the test server at http://term.ie - # echos back any non-oauth parameters but not the body. However, this does test that the request is still correctly signed - # (including the Content-Length header) and that the server received Content-Length bytes of body since it won't process the - # request & respond until the full body length is received. - end - - private - - def request_parameters_to_s - @request_parameters.map { |k, v| "#{k}=#{v}" }.join("&") - end -end diff --git a/test/units/consumer_test.rb b/test/units/consumer_test.rb deleted file mode 100644 index cb93505d..00000000 --- a/test/units/consumer_test.rb +++ /dev/null @@ -1,365 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -# This performs testing against Andy Smith's test server http://term.ie/oauth/example/ -# Thanks Andy. -# This also means you have to be online to be able to run these. -class ConsumerTest < Minitest::Test - def setup - @consumer = OAuth::Consumer.new( - "consumer_key_86cad9", "5888bf0345e5d237", - { - site: "http://blabla.bla", - proxy: "http://user:password@proxy.bla:8080", - request_token_path: "/oauth/example/request_token.php", - access_token_path: "/oauth/example/access_token.php", - authorize_path: "/oauth/example/authorize.php", - 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" } - @nonce = 225_579_211_881_198_842_005_988_698_334_675_835_446 - @timestamp = "1199645624" - @consumer.http = Net::HTTP.new(@request_uri.host, @request_uri.port) - end - - def test_initializer - assert_equal "consumer_key_86cad9", @consumer.key - assert_equal "5888bf0345e5d237", @consumer.secret - assert_equal "http://blabla.bla", @consumer.site - assert_equal "http://user:password@proxy.bla:8080", @consumer.proxy - assert_equal "/oauth/example/request_token.php", @consumer.request_token_path - assert_equal "/oauth/example/access_token.php", @consumer.access_token_path - assert_equal "http://blabla.bla/oauth/example/request_token.php", @consumer.request_token_url - assert_equal "http://blabla.bla/oauth/example/access_token.php", @consumer.access_token_url - assert_equal "http://blabla.bla/oauth/example/authorize.php", @consumer.authorize_url - assert_equal :header, @consumer.scheme - assert_equal :get, @consumer.http_method - assert_nil @consumer.debug_output - end - - def test_defaults - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - site: "http://twitter.com" - } - ) - assert_equal "key", @consumer.key - assert_equal "secret", @consumer.secret - assert_equal "http://twitter.com", @consumer.site - assert_nil @consumer.proxy - assert_equal "/oauth/request_token", @consumer.request_token_path - assert_equal "/oauth/access_token", @consumer.access_token_path - assert_equal "http://twitter.com/oauth/request_token", @consumer.request_token_url - assert_equal "http://twitter.com/oauth/access_token", @consumer.access_token_url - assert_equal "http://twitter.com/oauth/authorize", @consumer.authorize_url - assert_equal :header, @consumer.scheme - assert_equal :post, @consumer.http_method - assert_nil @consumer.debug_output - end - - def test_debug_output_true - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - debug_output: true - } - ) - assert_equal $stdout, @consumer.debug_output - end - - def test_debug_output - stringio = StringIO.new - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - debug_output: stringio - } - ) - assert_equal stringio, @consumer.debug_output - end - - def test_site_without_path - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - site: "http://twitter.com" - } - ) - request = stub(oauth!: nil) - http = stub(request: stub(to_hash: {}), address: "identi.ca") - Net::HTTP::Get.expects(:new).with("/people", {}).returns(request) - @consumer.expects(:create_http).returns(http) - @consumer.request(:get, "/people", nil, {}) - end - - def test_site_with_path - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - site: "http://identi.ca/api" - } - ) - request = stub(oauth!: nil) - http = stub(request: stub(to_hash: {}), address: "identi.ca") - Net::HTTP::Get.expects(:new).with("/api/people", {}).returns(request) - @consumer.expects(:create_http).returns(http) - @consumer.request(:get, "/people", nil, {}) - end - - def test_post_of_nested_params_maintains_nesting - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - site: "http://twitter.com" - } - ) - request = @consumer.create_signed_request( - :post, - "/people", - nil, - {}, - { - key: { - subkey: "value" - } - } - ) - assert_equal "key%5Bsubkey%5D=value", request.body - assert_equal("application/x-www-form-urlencoded", request.content_type) - end - - def test_override_paths - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - site: "http://twitter.com", - request_token_url: "http://oauth.twitter.com/request_token", - access_token_url: "http://oauth.twitter.com/access_token", - authorize_url: "http://site.twitter.com/authorize" - } - ) - assert_equal "key", @consumer.key - assert_equal "secret", @consumer.secret - assert_equal "http://twitter.com", @consumer.site - assert_equal "/oauth/request_token", @consumer.request_token_path - assert_equal "/oauth/access_token", @consumer.access_token_path - assert_equal "http://oauth.twitter.com/request_token", @consumer.request_token_url - assert_equal "http://oauth.twitter.com/access_token", @consumer.access_token_url - assert_equal "http://site.twitter.com/authorize", @consumer.authorize_url - assert_equal :header, @consumer.scheme - assert_equal :post, @consumer.http_method - end - - def test_getting_tokens_doesnt_add_paths_if_full_url_is_specified - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - site: "https://api.mysite.co.nz/v1", - request_token_url: "https://authentication.mysite.co.nz/Oauth/RequestToken" - } - ) - - stub_request(:post, "https://authentication.mysite.co.nz/Oauth/RequestToken").to_return(body: "success", - status: 200) - @consumer.get_request_token - end - - def test_noverify_true - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - site: "https://api.mysite.co.nz/v1", - request_token_url: "https://authentication.mysite.co.nz/Oauth/RequestToken", - no_verify: true - } - ) - - stub_request(:post, "https://authentication.mysite.co.nz/Oauth/RequestToken").to_return(body: "success", - status: 200) - - Net::HTTP.any_instance.expects(:"verify_mode=").with(OpenSSL::SSL::VERIFY_NONE) - - @consumer.get_request_token - end - - def test_noverify_false - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - site: "https://api.mysite.co.nz/v1", - request_token_url: "https://authentication.mysite.co.nz/Oauth/RequestToken", - no_verify: false - } - ) - - stub_request(:post, "https://authentication.mysite.co.nz/Oauth/RequestToken").to_return(body: "success", - status: 200) - - Net::HTTP.any_instance.expects(:"verify_mode=").with(OpenSSL::SSL::VERIFY_PEER) - @consumer.get_request_token - end - - def test_noverify_empty - @consumer = OAuth::Consumer.new( - "key", - "secret", - { - site: "https://api.mysite.co.nz/v1", - request_token_url: "https://authentication.mysite.co.nz/Oauth/RequestToken" - } - ) - - stub_request(:post, "https://authentication.mysite.co.nz/Oauth/RequestToken").to_return(body: "success", - status: 200) - - Net::HTTP.any_instance.expects(:"verify_mode=").with(OpenSSL::SSL::VERIFY_PEER) - @consumer.get_request_token - end - - 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) { nil } - assert request_options[:token_request] - end - - def test_that_token_response_should_be_uri_parameter_format_as_default - @consumer.expects(:request).returns(create_stub_http_response("oauth_token=token&oauth_token_secret=secret")) - - hash = @consumer.token_request(:get, "") - - assert_equal "token", hash[:oauth_token] - assert_equal "secret", hash[:oauth_token_secret] - end - - 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" } } - - 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, /.*#{redirect_url.path}/).to_return(body: "oauth_token=token&oauth_token_secret=secret") - - hash = @consumer.token_request(:get, @request_uri.path) do - { oauth_token: "token", oauth_token_secret: "secret" } - end - - 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, - "https://foobar.com/request_token").to_return(body: "oauth_token=token&oauth_token_secret=secret") - - hash = @consumer.token_request(:get, request_uri.path) do - { oauth_token: "token", oauth_token_secret: "secret" } - end - - assert_equal "token", hash[:oauth_token] - assert_equal "secret", hash[:oauth_token_secret] - end - - def test_not_following_redirect_with_same_uri - request_uri = URI.parse("http://example.com/request_token") - redirect_uri = request_uri.clone - - stub_request(:get, request_uri.to_s).to_return( - status: 301, - headers: { "Location" => redirect_uri.to_s } - ) - - assert_raises Net::HTTPRetriableError do - @consumer.token_request(:get, request_uri.path) do - { oauth_token: "token", oauth_token_secret: "secret" } - end - end - 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" } } - - assert_equal "token", token.token - assert_equal "secret", token.secret - end - - def test_that_block_is_not_mandatory_for_getting_an_access_token - stub_token = mock - @consumer.expects(:request).returns(create_stub_http_response("oauth_token=token&oauth_token_secret=secret")) - - token = @consumer.get_access_token(stub_token) - - 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" } } - - 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" } } - - 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" } } - - assert_nil request_options[:oauth_callback] - end - - private - - def create_stub_http_response(expected_body = nil) - stub_http_response = stub - stub_http_response.stubs(:code).returns(200) - stub_http_response.stubs(:body).tap do |expectation| - expectation.returns(expected_body) unless expected_body.nil? - end - stub_http_response - end -end diff --git a/test/units/curb_request_proxy_test.rb b/test/units/curb_request_proxy_test.rb deleted file mode 100644 index ed38b140..00000000 --- a/test/units/curb_request_proxy_test.rb +++ /dev/null @@ -1,77 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -begin - 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" }) - - expected_parameters = { "key" => ["value"] } - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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 }) - - expected_parameters = { "key" => "value" } - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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_proxy = OAuth::RequestProxy.proxy(request, { uri: "http://example.com/test" }) - - expected_parameters = { "key" => "value" } - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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 }) - - expected_parameters = { "key" => "value" } - assert_equal expected_parameters, request_proxy.parameters_for_signature - 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_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 - 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" } }) - - 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 - end - end -rescue LoadError => e - warn "! problems loading curb, skipping these tests: #{e}" -end diff --git a/test/units/em_http_client_test.rb b/test/units/em_http_client_test.rb deleted file mode 100644 index 559e550b..00000000 --- a/test/units/em_http_client_test.rb +++ /dev/null @@ -1,77 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" -begin - 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" } - @nonce = 225_579_211_881_198_842_005_988_698_334_675_835_446 - @timestamp = "1199645624" - # This is really unneeded I guess. - @http = Net::HTTP.new(@request_uri.host, @request_uri.port) - end - - 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 "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) - assert_equal_authz_headers correct_headers, generated_headers - end - - def test_that_using_auth_headers_on_get_requests_works_with_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" }) - - 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 - - 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_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]) - end - - protected - - def create_client(options = {}) - options[:method] = options.key?(:method) ? options[:method].upcase : "GET" - uri = options.delete(:uri) || @request_uri.to_s - EventMachine::HttpClient.new(URI.parse(uri), options) - end - - def authz_header(request) - request.req[:head]["Authorization"] - end - - def assert_equal_authz_headers(expected, actual) - refute_nil actual - assert_equal expected[0, 6], actual[0, 6] - assert_equal expected[6..1].split(", ").sort, actual[6..1].split(", ").sort - end - end -rescue LoadError => e - warn "! problem loading em-http, skipping these tests: #{e}" -end diff --git a/test/units/em_http_request_proxy_test.rb b/test/units/em_http_request_proxy_test.rb deleted file mode 100644 index 8c5db47d..00000000 --- a/test/units/em_http_request_proxy_test.rb +++ /dev/null @@ -1,118 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -begin - require "em-http" - require "oauth/request_proxy/em_http_request" - - class EmHttpRequestProxyTest < Minitest::Test - def test_request_proxy_works_with_simple_request - proxy = create_request_proxy - assert_empty(proxy.parameters) - end - - def test_request_proxy_works_with_query_string_params - assert_equal({ "name" => ["Fred"] }, create_request_proxy(query: "name=Fred").parameters) - assert_equal({ "name" => ["Fred"] }, create_request_proxy(query: { name: "Fred" }).parameters) - proxy = create_request_proxy(query: { name: "Fred" }, uri: "http://example.com/?awesome=true") - assert_equal({ "name" => ["Fred"], "awesome" => ["true"] }, proxy.parameters) - 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" - assert_empty(proxy.parameters) - 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 } - assert_equal({ "a" => ["1"] }, proxy.parameters) - proxy = create_request_proxy head: { "Content-Type" => "application/x-www-form-urlencoded" }, method: "PUT" - assert_empty(proxy.parameters) - 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 } - 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" - assert_empty(proxy.parameters) - proxy = create_request_proxy head: { "Content-Type" => "text/plain" }, method: "POST", body: "a=1" - assert_empty(proxy.parameters) - proxy = create_request_proxy head: { "Content-Type" => "text/plain" }, method: "POST", body: { "a" => 1 } - assert_empty(proxy.parameters) - proxy = create_request_proxy head: { "Content-Type" => "text/plain" }, method: "PUT" - assert_empty(proxy.parameters) - proxy = create_request_proxy head: { "Content-Type" => "text/plain" }, method: "PUT", body: "a=1" - assert_empty(proxy.parameters) - proxy = create_request_proxy head: { "Content-Type" => "text/plain" }, method: "PUT", body: { "a" => 1 } - assert_empty(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" - assert_empty(proxy.parameters) - proxy = create_request_proxy head: { "Content-Type" => "application/x-www-form-urlencoded" }, method: "DELETE", - body: "a=1" - assert_empty(proxy.parameters) - proxy = create_request_proxy head: { "Content-Type" => "application/x-www-form-urlencoded" }, method: "DELETE", - body: { "a" => 1 } - assert_empty(proxy.parameters) - proxy = create_request_proxy head: { "Content-Type" => "application/x-www-form-urlencoded" }, method: "GET" - assert_empty(proxy.parameters) - proxy = create_request_proxy head: { "Content-Type" => "application/x-www-form-urlencoded" }, method: "GET", - body: "a=1" - assert_empty(proxy.parameters) - proxy = create_request_proxy head: { "Content-Type" => "application/x-www-form-urlencoded" }, method: "GET", - body: { "a" => 1 } - assert_empty(proxy.parameters) - end - - def test_request_proxy_works_with_argument_params - assert_equal({ "a" => ["1"] }, - create_request_proxy(proxy_options: { parameters: { "a" => "1" } }).parameters) - end - - def test_request_proxy_works_with_mixed_params - proxy = create_request_proxy(proxy_options: { parameters: { "a" => "1" } }, query: { "c" => "1" }, - uri: "http://example.com/test?b=1") - assert_equal({ "a" => ["1"], "b" => ["1"], "c" => ["1"] }, proxy.parameters) - proxy = create_request_proxy(proxy_options: { parameters: { "a" => "1" } }, body: { "b" => "1" }, query: { "c" => "1" }, - uri: "http://example.com/test?d=1", method: "POST", head: { "Content-Type" => "application/x-www-form-urlencoded" }) - assert_equal({ "a" => ["1"], "b" => ["1"], "c" => ["1"], "d" => ["1"] }, proxy.parameters) - end - - def test_request_has_the_correct_uri - assert_equal "http://example.com/", create_request_proxy.uri - assert_equal "http://example.com/?a=1", create_request_proxy(query: "a=1").request.normalize_uri.to_s - assert_equal "http://example.com/?a=1", create_request_proxy(query: { "a" => "1" }).request.normalize_uri.to_s - end - - def test_request_proxy_has_correct_method - assert_equal "GET", create_request_proxy(method: "GET").request.req[:method] - assert_equal "PUT", create_request_proxy(method: "PUT").request.req[:method] - assert_equal "POST", create_request_proxy(method: "POST").request.req[:method] - assert_equal "DELETE", create_request_proxy(method: "DELETE").request.req[:method] - end - - protected - - def create_client(options = {}) - options[:method] = options.key?(:method) ? options[:method].upcase : "GET" - uri = options.delete(:uri) || "http://example.com/" - EventMachine::HttpClient.new(URI.parse(uri), options) - end - - def create_request_proxy(opts = {}) - arguments = opts.delete(:proxy_options) || {} - OAuth::RequestProxy.proxy(create_client(opts), arguments) - end - end -rescue LoadError => e - warn "! problem loading em-http, skipping these tests: #{e}" -end diff --git a/test/units/hmac_sha1_test.rb b/test/units/hmac_sha1_test.rb deleted file mode 100644 index e1cdfc13..00000000 --- a/test/units/hmac_sha1_test.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -class TestSignatureHmacSha1 < Minitest::Test - def test_that_hmac_sha1_implements_hmac_sha1 - assert_includes OAuth::Signature.available_methods, "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") - - 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" }) - - assert_equal "tR3+Ty81lMeYAr/Fid0kMTYa/WM=", signature - end -end diff --git a/test/units/hmac_sha256_test.rb b/test/units/hmac_sha256_test.rb deleted file mode 100644 index b6cb1416..00000000 --- a/test/units/hmac_sha256_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -class TestSignatureHmacSha256 < Minitest::Test - def test_that_hmac_sha256_implements_hmac_sha256 - assert_includes OAuth::Signature.available_methods, "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") - - 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" }) - - assert_equal "WVPzl1j6ZsnkIjWr7e3OZ3jkenL57KwaLFhYsroX1hg=", signature - end -end diff --git a/test/units/net_http_client_test.rb b/test/units/net_http_client_test.rb deleted file mode 100644 index 78469acf..00000000 --- a/test/units/net_http_client_test.rb +++ /dev/null @@ -1,340 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -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" } - @nonce = 225_579_211_881_198_842_005_988_698_334_675_835_446 - @timestamp = "1199645624" - @http = Net::HTTP.new(@request_uri.host, @request_uri.port) - end - - 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 - 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("OAuth", auth_intro) - assert_matching_headers correct_sorted_params, request["authorization"] - end - - def test_that_using_auth_headers_on_get_requests_works_with_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" }) - - 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 - request = Net::HTTP::Post.new(@request_uri.path) - 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 - 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"] - 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.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"] - 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"]) - 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"] - end - - def test_that_version_is_added_to_existing_user_agent - request = Net::HTTP::Post.new(@request_uri.path) - 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::VERSION})", request["User-Agent"] - end - - def test_that_version_is_set_when_no_user_agent - request = Net::HTTP::Post.new(@request_uri.path) - request.set_form_data(@request_parameters) - request.oauth!(@http, @consumer, @token, { nonce: @nonce, timestamp: @timestamp }) - - assert_equal "OAuth gem v#{OAuth::Version::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 }) - - assert_equal "GET", request.method - uri = URI.parse(request.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"] - 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" }) - - assert_equal "GET", request.method - uri = URI.parse(request.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"] - 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 }) - - 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"] - 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" }) - - 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"] - 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.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_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 }) - - assert_equal "POST", request.method - uri = URI.parse(request.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 "", request.body - 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.oauth!(@http, @consumer, @token, { scheme: :query_string, nonce: @nonce, timestamp: @timestamp }) - - assert_equal "POST", request.method - uri = URI.parse(request.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 "key2=value2", request.body - 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.oauth!(@http, @consumer, @token, { scheme: :query_string, nonce: @nonce, timestamp: @timestamp }) - - assert_equal "POST", request.method - uri = URI.parse(request.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"] - 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" - 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 - - # 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 - correct_sorted_params.unshift 'OAuth realm="http://photos.example.net/"' - assert_equal correct_sorted_params, request["authorization"].split(", ").sort - end - - def test_step_by_step_token_request - token_response = "oauth_token=requestkey&oauth_token_secret=requestsecret" - stub_request(:get, %r{http://term\.ie/oauth/example/request_token\.php(\?.*)?}).to_return(body: token_response) - - consumer = OAuth::Consumer.new( - "key", - "secret" - ) - 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) - - request = Net::HTTP::Get.new(request_uri.path) - signature_base_string = request.signature_base_string(http, consumer, nil, - { scheme: :query_string, nonce: nonce, timestamp: timestamp }) - assert_equal "GET&http%3A%2F%2Fterm.ie%2Foauth%2Fexample%2Frequest_token.php&oauth_consumer_key%3Dkey%26oauth_nonce%3D#{nonce}%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D#{timestamp}%26oauth_version%3D1.0", - signature_base_string - - # 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_nil request.body - 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) - assert_equal "200", response.code - # assert_equal request['authorization'],response.body - assert_equal token_response, response.body - end - - def test_that_put_bodies_signed - request = Net::HTTP::Put.new(@request_uri.path) - request.body = "baz" - request["Content-Type"] = "application/xml" - signature_base_string = request.signature_base_string(@http, @consumer, nil, - { nonce: @nonce, timestamp: @timestamp }) - assert_equal "PUT&http%3A%2F%2Fexample.com%2Ftest&oauth_body_hash%3DDvAa1AWdFoH9K%252B%252F2AHm3f6wH27k%253D%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_put_bodies_not_signed_even_if_form_urlencoded - request = Net::HTTP::Put.new(@request_uri.path) - 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" }) - 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 - - def test_that_post_bodies_signed_if_other_content_type - request = Net::HTTP::Post.new(@request_uri.path) - request.body = "baz" - request["Content-Type"] = "application/xml" - signature_base_string = request.signature_base_string(@http, @consumer, nil, - { nonce: @nonce, timestamp: @timestamp }) - assert_equal "POST&http%3A%2F%2Fexample.com%2Ftest&oauth_body_hash%3DDvAa1AWdFoH9K%252B%252F2AHm3f6wH27k%253D%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_not_signed_if_body_hash_disabled - request = Net::HTTP::Post.new(@request_uri.path) - request.body = "baz" - request["Content-Type"] = "application/xml" - signature_base_string = request.signature_base_string(@http, @consumer, nil, - { nonce: @nonce, timestamp: @timestamp, body_hash_enabled: false }) - assert_equal "POST&http%3A%2F%2Fexample.com%2Ftest&oauth_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_site_address_is_not_modified_in_place - 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] - assert_equal "http://api.twitter.com", options[:request_endpoint] - end - - protected - - def assert_no_match(exp, act, _deprecated = nil) - refute_match(exp, act) - end - - def request_parameters_to_s - @request_parameters.map { |k, v| "#{k}=#{v}" }.join("&") - end -end diff --git a/test/units/net_http_request_proxy_test.rb b/test/units/net_http_request_proxy_test.rb deleted file mode 100644 index 2f549bcc..00000000 --- a/test/units/net_http_request_proxy_test.rb +++ /dev/null @@ -1,74 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -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" }) - - 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 - 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 }) - - 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 - end - - def test_that_proxy_simple_post_request_works_with_form_data - 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" }) - - 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 - 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 }) - - 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 - end - - def test_that_proxy_simple_put_request_works_with_form_data - 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" }) - - 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 - 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" } }) - - 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 - end -end diff --git a/test/units/oauth_helper_test.rb b/test/units/oauth_helper_test.rb deleted file mode 100644 index 07f2613d..00000000 --- a/test/units/oauth_helper_test.rb +++ /dev/null @@ -1,112 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -class TestOAuthHelper < Minitest::Test - def test_parse_valid_header - header = "OAuth " \ - 'realm="http://example.com/method", ' \ - 'oauth_consumer_key="vince_clortho", ' \ - 'oauth_token="token_value", ' \ - 'oauth_signature_method="HMAC-SHA1", ' \ - 'oauth_signature="signature_here", ' \ - 'oauth_timestamp="1240004133", oauth_nonce="nonce", ' \ - 'oauth_version="1.0" ' - - 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"] - end - - def test_parse_header_ill_formed - header = "OAuth garbage" - - assert_raises OAuth::Problem do - OAuth::Helper.parse_header(header) - end - end - - def test_parse_header_contains_equals - header = "OAuth " \ - 'realm="http://example.com/method", ' \ - 'oauth_consumer_key="vince_clortho", ' \ - 'oauth_token="token_value", ' \ - 'oauth_signature_method="HMAC-SHA1", ' \ - 'oauth_signature="signature_here_with_=", ' \ - 'oauth_timestamp="1240004133", oauth_nonce="nonce", ' \ - 'oauth_version="1.0" ' - - assert_raises OAuth::Problem do - OAuth::Helper.parse_header(header) - end - end - - def test_parse_valid_header_with_and_signs - header = "OAuth " \ - 'realm="http://example.com/method"&' \ - 'oauth_consumer_key="vince_clortho"&' \ - 'oauth_token="token_value"&' \ - 'oauth_signature_method="HMAC-SHA1"&' \ - 'oauth_signature="signature_here"&' \ - 'oauth_timestamp="1240004133"&oauth_nonce="nonce"&' \ - 'oauth_version="1.0"' - - 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"] - 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" - } - 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_with_nested_array_of_hashes - params = { - "oauth_nonce" => "nonce", - "weight" => { value: "65" }, - "items" => [{ "a" => 1 }, { "b" => 2 }], - "oauth_signature_method" => "HMAC-SHA1", - "oauth_timestamp" => "1240004133", - "oauth_consumer_key" => "vince_clortho", - "oauth_token" => "token_value", - "oauth_version" => "1.0" - } - assert_equal( - "items%5B%5D%5Ba%5D=1&items%5B%5D%5Bb%5D=2&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_empty(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(["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")) - end -end diff --git a/test/units/rack_request_proxy_test.rb b/test/units/rack_request_proxy_test.rb deleted file mode 100644 index 54fc2525..00000000 --- a/test/units/rack_request_proxy_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -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" }) - - 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 - 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 }) - - 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 - 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 }) - - 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 - end -end diff --git a/test/units/request_token_test.rb b/test/units/request_token_test.rb deleted file mode 100644 index 2334753d..00000000 --- a/test/units/request_token_test.rb +++ /dev/null @@ -1,82 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -class StubbedToken < OAuth::RequestToken - define_method :build_url_promoted do |root_domain, params| - build_url root_domain, params - end -end - -class TestRequestToken < Minitest::Test - def setup - # setup a fake req. token. mocking Consumer would be more appropriate... - @request_token = OAuth::RequestToken.new( - OAuth::Consumer.new("key", "secret", {}), - "key", - "secret" - ) - end - - def test_request_token_builds_authorize_url_connectly_with_additional_params - auth_url = @request_token.authorize_url({ oauth_callback: "github.com" }) - assert auth_url - assert_match(/oauth_token/, auth_url) - assert_match(/oauth_callback/, auth_url) - end - - def test_request_token_builds_authorize_url_connectly_with_no_or_nil_params - # we should only have 1 key in the url returned if we didn't pass anything. - # this is the only required param to authenticate the client. - auth_url = @request_token.authorize_url(nil) - assert auth_url - assert_match(/\?oauth_token=/, auth_url) - - auth_url = @request_token.authorize_url - assert auth_url - assert_match(/\?oauth_token=/, auth_url) - end - - def test_request_token_returns_nil_authorize_url_when_token_is_nil - @request_token.token = nil - assert_nil @request_token.authorize_url - end - - def test_request_token_builds_authenticate_url_connectly_with_additional_params - authenticate_url = @request_token.authenticate_url({ oauth_callback: "github.com" }) - assert authenticate_url - assert_match(/oauth_token/, authenticate_url) - assert_match(/oauth_callback/, authenticate_url) - end - - def test_request_token_builds_authenticate_url_connectly_with_no_or_nil_params - # we should only have 1 key in the url returned if we didn't pass anything. - # this is the only required param to authenticate the client. - authenticate_url = @request_token.authenticate_url(nil) - assert authenticate_url - assert_match(/\?oauth_token=/, authenticate_url) - - authenticate_url2 = @request_token.authenticate_url - assert authenticate_url2 - assert_match(/\?oauth_token=/, authenticate_url2) - end - - def test_request_token_returns_nil_authenticate_url_when_token_is_nil - @request_token.token = nil - assert_nil @request_token.authenticate_url - end - - # TODO: mock out the Consumer to test the Consumer/AccessToken interaction. - def test_get_access_token; end - - def test_build_url - @stubbed_token = StubbedToken.new(nil, nil, nil) - assert_respond_to @stubbed_token, :build_url_promoted - url = @stubbed_token.build_url_promoted( - "http://github.com/oauth/authorize", - { foo: "bar bar" } - ) - assert url - assert_equal "http://github.com/oauth/authorize?foo=bar+bar", url - end -end diff --git a/test/units/rest_client_request_proxy_test.rb b/test/units/rest_client_request_proxy_test.rb deleted file mode 100644 index 94ddd82d..00000000 --- a/test/units/rest_client_request_proxy_test.rb +++ /dev/null @@ -1,90 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -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" }) - - 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 - 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 }) - - 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 - 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" }) - - 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 - end - - def test_that_proxy_simple_post_request_ignores_non_form_data_payload - request = ::RestClient::Request.new( - method: :post, url: "http://example.com/test", payload: '{"key": "value"}', headers: { content_type: :json } - ) - request_proxy = OAuth::RequestProxy.proxy(request, { uri: "http://example.com/test" }) - - assert_empty request_proxy.parameters_for_signature - 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 }) - - 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 - 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" }) - - 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 - end - - def test_that_proxy_post_request_works_with_mixed_parameter_sources - 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" } }) - - 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 - end -end diff --git a/test/units/rsa_sha1_test.rb b/test/units/rsa_sha1_test.rb deleted file mode 100644 index e90b47da..00000000 --- a/test/units/rsa_sha1_test.rb +++ /dev/null @@ -1,81 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -require "oauth/consumer" -require "oauth/signature/rsa/sha1" - -class TestSignatureRsaSha1 < Minitest::Test - def setup - @request = Net::HTTP::Get.new("/photos?file=vacaction.jpg&size=original&oauth_version=1.0&oauth_consumer_key=#{consumer_key}&oauth_timestamp=1196666512&oauth_nonce=13917289812797014437&oauth_signature_method=RSA-SHA1") - - @consumer = OAuth::Consumer.new(consumer_key, pkey_rsa) - end - - def test_that_rsa_sha1_implements_rsa_sha1 - assert_includes OAuth::Signature.available_methods, "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" }) - - 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" }) - - 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 - @consumer = OAuth::Consumer.new(consumer_key, nil) - - signature = OAuth::Signature.sign(@request, { consumer: @consumer, - private_key_file: pem_path, - uri: "http://photos.example.net/photos" }) - - assert_equal "jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=", - signature - end - - def test_that_get_request_from_oauth_test_cases_verifies_signature - @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") - @consumer = OAuth::Consumer.new(consumer_key, x509_certificate) - - assert OAuth::Signature.verify(@request, { consumer: @consumer, - 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" }) - end - - private - - def consumer_key - "dpf43f3p2l4k3l03" - end - - def x509_certificate - OpenSSL::X509::Certificate.new(File.read(cert_path)) - end - - def pkey_rsa - OpenSSL::PKey::RSA.new(File.read(pem_path)) - end - - def cert_path - "#{File.dirname(__FILE__)}/../keys/rsa.cert" - end - - def pem_path - "#{File.dirname(__FILE__)}/../keys/rsa.pem" - end -end diff --git a/test/units/server_test.rb b/test/units/server_test.rb deleted file mode 100644 index 34814aa4..00000000 --- a/test/units/server_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -require "oauth/server" - -class ServerTest < Minitest::Test - def setup - @server = OAuth::Server.new "http://test.com" - end - - def test_default_paths - assert_equal "/oauth/request_token", @server.request_token_path - assert_equal "/oauth/authorize", @server.authorize_path - assert_equal "/oauth/access_token", @server.access_token_path - end - - def test_default_urls - assert_equal "http://test.com/oauth/request_token", @server.request_token_url - assert_equal "http://test.com/oauth/authorize", @server.authorize_url - assert_equal "http://test.com/oauth/access_token", @server.access_token_url - end - - def test_generate_consumer_credentials - consumer = @server.generate_consumer_credentials - assert consumer.key - assert consumer.secret - end - - def test_create_consumer - @consumer = @server.create_consumer - assert @consumer - assert @consumer.key - assert @consumer.secret - assert_equal "http://test.com", @consumer.site - assert_equal "/oauth/request_token", @consumer.request_token_path - assert_equal "/oauth/authorize", @consumer.authorize_path - assert_equal "/oauth/access_token", @consumer.access_token_path - assert_equal "http://test.com/oauth/request_token", @consumer.request_token_url - assert_equal "http://test.com/oauth/authorize", @consumer.authorize_url - assert_equal "http://test.com/oauth/access_token", @consumer.access_token_url - end -end diff --git a/test/units/signature_base_test.rb b/test/units/signature_base_test.rb deleted file mode 100644 index bd71c648..00000000 --- a/test/units/signature_base_test.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -require "oauth/signature/base" -require "net/http" - -class SignatureBaseTest < Minitest::Test - def test_that_initialize_requires_one_request_argument - assert_raises ArgumentError do - OAuth::Signature::Base.new - end - end - - def test_that_initialize_requires_a_valid_request_argument - request = nil - assert_raises TypeError do - OAuth::Signature::Base.new(request) do |token| - # just a stub - end - end - end - - 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") - request = OAuth::RequestProxy.proxy(raw_request) - - OAuth::Signature::Base.new(request) do |token| - # just a stub - end - end -end diff --git a/test/units/signature_hmac_sha1_test.rb b/test/units/signature_hmac_sha1_test.rb deleted file mode 100644 index 71b79379..00000000 --- a/test/units/signature_hmac_sha1_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -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=" - } - ) - 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=" - } - ) - refute OAuth::Signature::HMAC::SHA1.new(request, consumer_secret: "kd94hf93k423kf44").verify - end -end diff --git a/test/units/signature_hmac_sha256_test.rb b/test/units/signature_hmac_sha256_test.rb deleted file mode 100644 index e5850522..00000000 --- a/test/units/signature_hmac_sha256_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -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=" - } - ) - 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=" - } - ) - refute OAuth::Signature::HMAC::SHA256.new(request, consumer_secret: "kd94hf93k423kf44").verify - end -end diff --git a/test/units/signature_plain_text_test.rb b/test/units/signature_plain_text_test.rb deleted file mode 100644 index c2993d32..00000000 --- a/test/units/signature_plain_text_test.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -class TestSignaturePlaintext < Minitest::Test - def test_that_plaintext_implements_plaintext - assert_includes OAuth::Signature.available_methods, "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") - - 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" }) - 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") - - 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" }) - end -end diff --git a/test/units/signature_test.rb b/test/units/signature_test.rb deleted file mode 100644 index a38cff15..00000000 --- a/test/units/signature_test.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -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("あ"), - "Failed to correctly escape Japanese under $KCODE = #{kcode}" - assert_equal "%C3%A9", OAuth::Helper.escape("é"), - "Failed to correctly escape e+acute under $KCODE = #{kcode}" - end - end -end diff --git a/test/units/token_test.rb b/test/units/token_test.rb deleted file mode 100644 index ec55ab7b..00000000 --- a/test/units/token_test.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -require "oauth/token" - -class TokenTest < Minitest::Test - 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 - end -end diff --git a/test/units/typhoeus_request_proxy_test.rb b/test/units/typhoeus_request_proxy_test.rb deleted file mode 100644 index da1200c5..00000000 --- a/test/units/typhoeus_request_proxy_test.rb +++ /dev/null @@ -1,102 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -begin - 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" }) - - 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 - 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 }) - - 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 - 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" }) - - 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 - 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 }) - - 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 - 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" }) - - 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 - 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 }) - - 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 - 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" }) - - 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 - end - - def test_that_proxy_post_request_works_with_mixed_parameter_sources - 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" } }) - - 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 - end - end -rescue LoadError => e - warn "! problem loading typhoeus, skipping these tests: #{e}" -end From ad7632341e2e1e802335678965dd019c214e5a32 Mon Sep 17 00:00:00 2001 From: Peter Boling Date: 2022年9月19日 10:02:32 +0700 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=8E=89=20Migration=20from=20Github=20?= =?UTF-8?q?to=20Gitlab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9667502..56fe1a93 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ git remote set-url origin git@gitlab.com:oauth-xx/oauth.git * Live Chat on Gitter: [![Join the chat at https://gitter.im/oauth-xx/oauth-ruby](https://badges.gitter.im/Join%20Chat.svg)][chat] * Maintainer's Blog: [![Blog](https://img.shields.io/badge/blog-railsbling-brightgreen.svg?style=flat)][blogpage] -[documentation]: https://rubydoc.info/github/oauth-xx/oauth-ruby +[documentation]: https://rubydoc.info/gems/oauth [mailinglist]: http://groups.google.com/group/oauth-ruby [chat]: https://gitter.im/oauth-xx/oauth-ruby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge [blogpage]: http://www.railsbling.com/tags/oauth/

AltStyle によって変換されたページ (->オリジナル) /