rack-alice_in_external 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.md +20 -0
- data/README.md +107 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rack/alice_in_external/github_mock.rb +16 -0
- data/lib/rack/alice_in_external/version.rb +5 -0
- data/lib/rack/alice_in_external/webmock_stubs.rb +15 -0
- data/lib/rack/alice_in_external.rb +10 -0
- data/rack-alice_in_external.gemspec +26 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d5f472777dfd1626cd1c5bdf129acf580c850d75
|
4
|
+
data.tar.gz: 0198a1bacee53b5d7a2205d94482bfefe3b38171
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c674d5972cac42b7b620aa189e32fa61cf96db3b92a74af166a1a2e70d24c60ffcd7d6b17fa433f01da1c111c4cac9ee6edb273f2afeb6a5b6c6cad927ced1f
|
7
|
+
data.tar.gz: 230fe6d1414e4d94027bfb3e9bfd3878af631f53751e3010a3bbf9c8d0d1bb489cb1b1ca064c1a5481880e873f7c4c509c6cdc9818cdb98fc114536c4c6e0eea
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Hirofumi Wakasugi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# Rack::AliceInExternal
|
2
|
+
|
3
|
+
Rack::AliceInExternal is a Rack middleware which provides rough and dirty stubbing for authentication via [Sorcery](https://github.com/NoamB/sorcery) external (GitHub OAuth only for the moment).
|
4
|
+
|
5
|
+
Assumes that you have built the `OauthsController` following to https://github.com/NoamB/sorcery/wiki/External :
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
class OauthsController < ApplicationController
|
9
|
+
|
10
|
+
...
|
11
|
+
|
12
|
+
def oauth
|
13
|
+
|
14
|
+
...
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def callback
|
19
|
+
|
20
|
+
...
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
...
|
25
|
+
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
Rack::AliceInExternal hooks requests for `/oauth/[provider]` and returns the stubbed response which redirects you to `/oauth/callback?provider=[provider]`.
|
30
|
+
|
31
|
+
Then `callback` action tries to acquire the access token for authentication from the provider, Rack::AliceInExternal stubs those requests via [WebMock](https://github.com/bblimke/webmock) and returns the response of the access token and the user data that can be appropriately handled by Sorcery.
|
32
|
+
|
33
|
+
This helps you to write feature tests in more user-story-friendly ways, like:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
visit root_url
|
37
|
+
click_link 'Login with GitHub'
|
38
|
+
...
|
39
|
+
```
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
|
43
|
+
Add this line to your application's Gemfile:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
gem 'rack-alice_in_external'
|
47
|
+
```
|
48
|
+
|
49
|
+
## Usage
|
50
|
+
|
51
|
+
Rack::AliceInExternal tries to find the user who has an association with `uid: 42` in `authentications` table, so you have to create that user and the authentication associated to her (and you cannot change `uid` other than `42`) .
|
52
|
+
|
53
|
+
Fixture examples:
|
54
|
+
|
55
|
+
__users.yml__
|
56
|
+
|
57
|
+
```yaml
|
58
|
+
alice:
|
59
|
+
name: Alice
|
60
|
+
```
|
61
|
+
|
62
|
+
__authentications.yml__
|
63
|
+
|
64
|
+
|
65
|
+
```yaml
|
66
|
+
alice_auth:
|
67
|
+
uid: 42
|
68
|
+
provider: github
|
69
|
+
user: alice
|
70
|
+
```
|
71
|
+
|
72
|
+
Add the middleware you want to use for stubbing in `config/environments/test.rb` (add it in `development.rb` as well if necessary):
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
Rails.application.configure do
|
76
|
+
|
77
|
+
...
|
78
|
+
|
79
|
+
|
80
|
+
# Stubbing OAuth authentication via Sorcery's GitHub external
|
81
|
+
config.middleware.use Rack::AliceInExternal::GithubMock
|
82
|
+
|
83
|
+
...
|
84
|
+
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
Then just write feature tests like the below, it tries to login as the user with `uid: 42`:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
visit root_url
|
92
|
+
click_link 'Login with GitHub' # <= the link to /oauth/[provider]
|
93
|
+
|
94
|
+
...
|
95
|
+
|
96
|
+
```
|
97
|
+
|
98
|
+
## Development
|
99
|
+
|
100
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
101
|
+
|
102
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
103
|
+
|
104
|
+
## Contributing
|
105
|
+
|
106
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/5t111111/rack-alice_in_external.
|
107
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rack/alice_in_external"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Rack
|
2
|
+
module AliceInExternal
|
3
|
+
class GithubMock
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
if env['PATH_INFO'] =~ %r{\A.*/oauth/github/?\z}
|
10
|
+
return [301, { 'Location' => '/oauth/callback?provider=github' }, []]
|
11
|
+
end
|
12
|
+
@app.call(env)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'webmock'
|
2
|
+
|
3
|
+
include WebMock::API
|
4
|
+
|
5
|
+
# Stubbing external request for GitHub OAuth via WebMock
|
6
|
+
stub_request(:post, 'https://github.com/login/oauth/access_token')
|
7
|
+
.to_return(body: 'access_token=charleslutwidgedodgson&scope=user%2Cgist&token_type=bearer',
|
8
|
+
headers: { 'content-type' => 'application/x-www-form-urlencoded' })
|
9
|
+
|
10
|
+
stub_request(:get, 'https://api.github.com/user')
|
11
|
+
.to_return(body:'{"id":42,"email":"alice@example.com"}',
|
12
|
+
headers: { 'content-type' => 'application/json' })
|
13
|
+
|
14
|
+
WebMock.enable!
|
15
|
+
WebMock.allow_net_connect!
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Stubbing authentication via Sorcery external
|
2
|
+
#
|
3
|
+
# Assume you have built the controller following to the below post:
|
4
|
+
# https://github.com/NoamB/sorcery/wiki/External
|
5
|
+
#
|
6
|
+
# Requires a user has an associtation with authentications(uid: 42)
|
7
|
+
|
8
|
+
require 'rack/alice_in_external/version'
|
9
|
+
require 'rack/alice_in_external/webmock_stubs'
|
10
|
+
require 'rack/alice_in_external/github_mock'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/alice_in_external/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack-alice_in_external"
|
8
|
+
spec.version = Rack::AliceInExternal::VERSION
|
9
|
+
spec.authors = ["Hirofumi Wakasugi"]
|
10
|
+
spec.email = ["baenej@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Rough and dirty stubbing for authentication via Sorcery external}
|
13
|
+
spec.description = %q{Rough and dirty stubbing for authentication via Sorcery external (GitHub only for the moment)}
|
14
|
+
spec.homepage = "https://github.com/5t111111/rack-alice_in_external"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "webmock", "~> 2.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-alice_in_external
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hirofumi Wakasugi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: webmock
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
description: Rough and dirty stubbing for authentication via Sorcery external (GitHub
|
70
|
+
only for the moment)
|
71
|
+
email:
|
72
|
+
- baenej@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.md
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/rack/alice_in_external.rb
|
86
|
+
- lib/rack/alice_in_external/github_mock.rb
|
87
|
+
- lib/rack/alice_in_external/version.rb
|
88
|
+
- lib/rack/alice_in_external/webmock_stubs.rb
|
89
|
+
- rack-alice_in_external.gemspec
|
90
|
+
homepage: https://github.com/5t111111/rack-alice_in_external
|
91
|
+
licenses: []
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.5.1
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Rough and dirty stubbing for authentication via Sorcery external
|
113
|
+
test_files: []
|