opensesame 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -8
- data/app/assets/stylesheets/open_sesame/{application.css → opensesame.css} +0 -1
- data/app/assets/stylesheets/open_sesame/{welcome.css.scss → welcome.css} +50 -1
- data/app/controllers/open_sesame/application_controller.rb +1 -1
- data/app/controllers/open_sesame/sessions_controller.rb +22 -5
- data/app/helpers/open_sesame/application_helper.rb +1 -1
- data/app/views/layouts/open_sesame/application.html.erb +1 -2
- data/config/routes.rb +2 -2
- data/lib/open_sesame/configuration.rb +10 -13
- data/lib/open_sesame/engine.rb +21 -22
- data/lib/open_sesame/failure/app.rb +10 -0
- data/lib/open_sesame/failure/devise_app.rb +17 -0
- data/lib/open_sesame/github_auth.rb +9 -0
- data/lib/open_sesame/github_warden.rb +26 -0
- data/lib/open_sesame/{controller_helper.rb → helpers/controller_helper.rb} +2 -1
- data/lib/open_sesame/{view_helper.rb → helpers/view_helper.rb} +4 -3
- data/lib/open_sesame/member.rb +65 -0
- data/lib/open_sesame/version.rb +2 -1
- data/lib/open_sesame.rb +16 -4
- data/spec/dummy/app/views/home/index.html.erb +3 -1
- data/spec/dummy/config/initializers/opensesame.rb +16 -2
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/dummy/config/routes.rb +1 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/log/development.log +135 -6
- data/spec/dummy/log/test.log +41874 -530
- data/spec/dummy/tmp/cache/assets/C09/2F0/sprockets%2F76045b33d436a11b0156b36a91560651 +0 -0
- data/spec/dummy/tmp/cache/assets/C54/300/sprockets%2Fb83307a70e6040f817087f997dc73122 +0 -0
- data/spec/dummy/tmp/cache/assets/CAA/920/sprockets%2Ff2904820584f0723f5ab256dcf1a9225 +0 -0
- data/spec/dummy/tmp/cache/assets/CC2/790/sprockets%2F020f956f67983c52c9889ac9801ca4b4 +0 -0
- data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/CEC/240/sprockets%2Fdec29f626939d38247d1745e057c6ab2 +0 -0
- data/spec/dummy/tmp/cache/assets/D0C/2A0/sprockets%2F04922c120a656b333dd5fcd28c9f8f53 +0 -0
- data/spec/dummy/tmp/cache/assets/D12/EF0/sprockets%2F98d5a511dcf32074eef97c372f294a20 +0 -0
- data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/D38/DB0/sprockets%2Fe4441bec5b04f6a4ad4bf7056181558e +0 -0
- data/spec/dummy/tmp/cache/assets/D45/CE0/sprockets%2F6c1b76a50b27d5e7485d41cef59eb427 +0 -0
- data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/D60/400/sprockets%2F1f456ac6c7c736a4407ead0832adb42c +0 -0
- data/spec/dummy/tmp/cache/assets/D72/880/sprockets%2Fe5615e8c12de3dbb5626aee43388cb39 +0 -0
- data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/DDD/910/sprockets%2Ff8ed9a8d47ac232db51e9c7adb8377a9 +0 -0
- data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/E09/D90/sprockets%2Fd85890cff0dcafde74d69601baae198e +0 -0
- data/spec/dummy/tmp/cache/assets/E3C/B20/sprockets%2Fde9e6fc28cd2dfe38cc53fd0455b5b9e +0 -0
- data/spec/dummy/tmp/cache/sass/19921c2f5bb8eaa817ba254313d0f93dbf32f1df/opensesame.css.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/19921c2f5bb8eaa817ba254313d0f93dbf32f1df/opensesame_bootstrap.css.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_accordion.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_alerts.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_breadcrumbs.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_button-groups.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_buttons.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_carousel.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_close.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_code.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_component-animations.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_dropdowns.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_forms.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_grid.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_hero-unit.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_labels-badges.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_layouts.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_mixins.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_modals.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_navbar.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_navs.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_pager.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_pagination.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_popovers.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_progress-bars.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_reset.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_scaffolding.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_sprites.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_tables.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_thumbnails.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_tooltip.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_type.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_utilities.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_variables.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_wells.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/c0430781249a04c227e0b0aca38159d7478590b1/_bootstrap.scssc +0 -0
- data/spec/dummy/tmp/capybara/{capybara-201205020845417136358435.html → capybara-201208201553167621643394.html} +2 -0
- data/spec/lib/open_sesame/configuration_spec.rb +0 -40
- data/spec/lib/open_sesame/github_auth_spec.rb +30 -0
- data/spec/lib/open_sesame/github_warden_spec.rb +44 -0
- data/spec/lib/open_sesame/member_spec.rb +51 -0
- data/spec/lib/open_sesame/sessions_spec.rb +23 -8
- data/spec/lib/open_sesame_spec.rb +7 -2
- data/spec/spec_helper.rb +0 -3
- data/spec/support/capybara.rb +24 -0
- data/spec/support/request_helpers.rb +61 -0
- data/spec/support/vcr.rb +22 -0
- data/spec/vcr/member/retrieves_attributes_from_github.yml +46 -0
- data/spec/vcr/member/returns_nil_if_no_github_member_found.yml +46 -0
- data/spec/vcr/member/serialize_from_session_returns_member_from_given_member_id.yml +89 -0
- data/spec/vcr/member/serialize_into_session_returns_given_member_id_in_array.yml +46 -0
- data/spec/vcr/session/allows_auto_login.yml +132 -0
- data/spec/vcr/session/enforces_opensesame_login.yml +132 -0
- data/spec/vcr/session/skips_auto_login_if_just_logged_out.yml +175 -0
- data/spec/vcr/session/tries_auto_login_and_ends_up_on_opensesame_page_after_failure.yml +46 -0
- metadata +239 -41
- data/app/assets/javascripts/open_sesame/application.js +0 -15
- data/app/assets/stylesheets/open_sesame/opensesame_bootstrap.css.scss +0 -8
- data/lib/open_sesame/failure_app.rb +0 -14
- data/spec/dummy/tmp/capybara/capybara-201205020845084431324775.html +0 -14
- data/spec/dummy/tmp/capybara/capybara-201205020846032430049397.html +0 -14
- data/spec/dummy/tmp/capybara/capybara-201205020848165144257335.html +0 -26
- data/spec/dummy/tmp/capybara/capybara-201205020849371072293414.html +0 -26
- data/spec/dummy/tmp/capybara/capybara-201205020851069360249571.html +0 -26
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/spec/dummy/tmp/cache/sass/bf8de80767f3492905bcacdfb6abfd679aef3272/_component-animations.scssc
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -62,7 +62,6 @@ describe OpenSesame::Configuration do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
describe "enabled?" do
|
65
|
-
let(:conditional) { mock('conditional', :true? => true) }
|
66
65
|
|
67
66
|
it { configuration.enabled?.should be_false }
|
68
67
|
|
@@ -76,44 +75,5 @@ describe OpenSesame::Configuration do
|
|
76
75
|
configuration.should_not be_enabled
|
77
76
|
end
|
78
77
|
|
79
|
-
it "false if enable_if clause is false" do
|
80
|
-
conditional.stub!(:true?).and_return(false)
|
81
|
-
configuration.enable_if conditional.true?
|
82
|
-
configuration.should_not be_enabled
|
83
|
-
end
|
84
|
-
|
85
|
-
it "true if enable_if clause is true" do
|
86
|
-
conditional.stub!(:true?).and_return(true)
|
87
|
-
configuration.enable_if conditional.true?
|
88
|
-
configuration.should be_enabled
|
89
|
-
end
|
90
|
-
|
91
|
-
it "true if enable_if clause is false but then enabled!" do
|
92
|
-
conditional.stub!(:true?).and_return(false)
|
93
|
-
configuration.enable_if conditional.true?
|
94
|
-
configuration.enable!
|
95
|
-
configuration.should be_enabled
|
96
|
-
end
|
97
|
-
|
98
|
-
it "false if enable_if clause is true but then disabled!" do
|
99
|
-
conditional.stub!(:true?).and_return(true)
|
100
|
-
configuration.enable_if conditional.true?
|
101
|
-
configuration.disable!
|
102
|
-
configuration.should_not be_enabled
|
103
|
-
end
|
104
|
-
|
105
|
-
it "false if enabled! then supplied with enable_if clause that is false" do
|
106
|
-
configuration.enable!
|
107
|
-
conditional.stub!(:true?).and_return(false)
|
108
|
-
configuration.enable_if conditional.true?
|
109
|
-
configuration.should_not be_enabled
|
110
|
-
end
|
111
|
-
|
112
|
-
it "true if disabled! then supplied with enable_if clause that is true" do
|
113
|
-
configuration.disable!
|
114
|
-
conditional.stub!(:true?).and_return(true)
|
115
|
-
configuration.enable_if conditional.true?
|
116
|
-
configuration.should be_enabled
|
117
|
-
end
|
118
78
|
end
|
119
79
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe OpenSesame::GithubAuth do
|
5
|
+
subject do
|
6
|
+
OpenSesame::GithubAuth.new({})
|
7
|
+
end
|
8
|
+
|
9
|
+
context "client options" do
|
10
|
+
it 'should have correct site' do
|
11
|
+
subject.options.client_options.site.should eq("https://api.github.com")
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should have correct authorize url' do
|
15
|
+
subject.options.client_options.authorize_url.should eq('https://github.com/login/oauth/authorize')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should have correct token url' do
|
19
|
+
subject.options.client_options.token_url.should eq('https://github.com/login/oauth/access_token')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should have /opensesame path_prefix' do
|
24
|
+
subject.options.path_prefix.should eq('/opensesame')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should have name github' do
|
28
|
+
subject.options.name.should eq('github')
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenSesame::GithubWarden do
|
4
|
+
|
5
|
+
let(:strategy) { OpenSesame::GithubWarden.new(@env_with_params) }
|
6
|
+
|
7
|
+
it "is not valid without omniauth hash" do
|
8
|
+
@env_with_params = env_with_params("/", {}, 'omniauth.auth' => nil)
|
9
|
+
strategy.valid?.should be_false
|
10
|
+
end
|
11
|
+
|
12
|
+
it "is not valid without github provider in omniauth hash" do
|
13
|
+
@env_with_params = env_with_params("/", {}, 'omniauth.auth' => {})
|
14
|
+
strategy.valid?.should be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "is valid with github provider in omniauth hash" do
|
18
|
+
@env_with_params = env_with_params("/", {}, 'omniauth.auth' => { "provider" => "github" })
|
19
|
+
strategy.valid?.should be_true
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns omniauth auth_hash" do
|
23
|
+
@env_with_params = env_with_params("/", {}, 'omniauth.auth' => { "provider" => "github" })
|
24
|
+
strategy.auth_hash.should eq("provider" => "github")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "authenticates successfully when OpenSesame::Member is found" do
|
28
|
+
@env_with_params = env_with_params("/", {}, 'omniauth.auth' => { "provider" => "github", "uid" => "123" })
|
29
|
+
|
30
|
+
OpenSesame::Member.should_receive(:find).with("123").and_return(OpenSesame::Member.new(:id => "123"))
|
31
|
+
strategy.authenticate!
|
32
|
+
strategy.result.should == :success
|
33
|
+
end
|
34
|
+
|
35
|
+
it "fails authentication when OpenSesame::Member is not found" do
|
36
|
+
@env_with_params = env_with_params("/", {}, 'omniauth.auth' => { "provider" => "github", "uid" => "123" })
|
37
|
+
OpenSesame::Member.should_receive(:find).with("123").and_return(nil)
|
38
|
+
|
39
|
+
strategy.authenticate!
|
40
|
+
strategy.result.should == :failure
|
41
|
+
strategy.message.should == 'Sorry, you do not have access'
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OpenSesame::Member, :vcr, :record => :new_episodes do
|
4
|
+
ROSSTA_GITHUB_ID = 11673
|
5
|
+
|
6
|
+
describe "self.find" do
|
7
|
+
it "retrieves attributes from github" do
|
8
|
+
member = OpenSesame::Member.find(ROSSTA_GITHUB_ID)
|
9
|
+
member.should be_a(OpenSesame::Member)
|
10
|
+
member.id.should == ROSSTA_GITHUB_ID
|
11
|
+
member.login.should == 'rossta'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns nil if no github member found" do
|
15
|
+
nonexisting_id = -1
|
16
|
+
member = OpenSesame::Member.find(nonexisting_id)
|
17
|
+
member.should be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
context "github api" do
|
21
|
+
let(:github_api) { mock('Octokit') }
|
22
|
+
|
23
|
+
before do
|
24
|
+
OpenSesame::Member.stub!(:github_api => github_api)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "looks up organization member for given id" do
|
28
|
+
github_api.should_receive(:organization_members).with(OpenSesame.organization_name).and_return([])
|
29
|
+
OpenSesame::Member.find(123)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "skips lookup if no id given" do
|
33
|
+
github_api.should_not_receive(:organization_members)
|
34
|
+
OpenSesame::Member.find(nil)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "warden serialization" do
|
40
|
+
let(:member) { OpenSesame::Member.find(ROSSTA_GITHUB_ID) }
|
41
|
+
|
42
|
+
it "serialize_into_session returns given member.id in array" do
|
43
|
+
OpenSesame::Member.serialize_into_session(member).should eq([ROSSTA_GITHUB_ID])
|
44
|
+
end
|
45
|
+
|
46
|
+
it "serialize_from_session returns member from given member id" do
|
47
|
+
OpenSesame::Member.serialize_from_session(ROSSTA_GITHUB_ID).should eq(member)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Session", :type => :request do
|
3
|
+
describe "Session", :vcr, :record => :new_episodes, :type => :request do
|
4
4
|
|
5
5
|
context "successful login" do
|
6
|
-
before { setup_for_github_login }
|
6
|
+
before { setup_for_github_login }
|
7
7
|
|
8
8
|
it "enforces opensesame login" do
|
9
9
|
visit root_path
|
@@ -15,16 +15,31 @@ describe "Session", :type => :request do
|
|
15
15
|
page.should have_content "Welcome Home"
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
OpenSesame.stub!(:auto_access_provider).and_return('github')
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
describe "auto login" do
|
19
|
+
before { OpenSesame.stub!(:auto_access_provider).and_return('github') }
|
20
|
+
|
21
|
+
it "allows auto login" do
|
22
|
+
visit root_path
|
23
|
+
page.should have_content "Welcome Home"
|
24
|
+
end
|
23
25
|
|
26
|
+
it "skips auto login if just logged out" do
|
27
|
+
visit root_path
|
28
|
+
|
29
|
+
click_link "Logout"
|
30
|
+
|
31
|
+
page.should_not have_content "Welcome Home"
|
32
|
+
page.should have_content "Login"
|
33
|
+
|
34
|
+
visit root_path # auto login now works on refresh
|
35
|
+
page.should have_content "Welcome Home"
|
36
|
+
page.should_not have_content "Login"
|
37
|
+
end
|
38
|
+
end
|
24
39
|
end
|
25
40
|
|
26
41
|
it "tries auto login and ends up on opensesame page after failure" do
|
27
|
-
|
42
|
+
setup_for_github_login(mock('NonUser', :id => "123"))
|
28
43
|
visit root_path
|
29
44
|
page.should have_content "Login"
|
30
45
|
page.should_not have_content "Welcome Home"
|
@@ -5,6 +5,11 @@ describe OpenSesame do
|
|
5
5
|
it { defined?(OpenSesame).should be_true }
|
6
6
|
|
7
7
|
it { defined?(OpenSesame::Configuration).should be_true }
|
8
|
-
it { defined?(OpenSesame::
|
9
|
-
it { defined?(OpenSesame::
|
8
|
+
it { defined?(OpenSesame::GithubAuth).should be_true }
|
9
|
+
it { defined?(OpenSesame::GithubWarden).should be_true }
|
10
|
+
it { defined?(OpenSesame::Member).should be_true }
|
11
|
+
it { defined?(OpenSesame::Failure::App).should be_true }
|
12
|
+
it { defined?(OpenSesame::Failure::DeviseApp).should be_true }
|
13
|
+
it { defined?(OpenSesame::Helpers::ControllerHelper).should be_true }
|
14
|
+
it { defined?(OpenSesame::Helpers::ViewHelper).should be_true }
|
10
15
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,7 +5,6 @@ require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
|
5
5
|
require 'rspec/rails'
|
6
6
|
require 'rspec/autorun'
|
7
7
|
require 'capybara/rspec'
|
8
|
-
require 'opensesame-github/capybara'
|
9
8
|
|
10
9
|
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
11
10
|
|
@@ -18,6 +17,4 @@ OmniAuth.config.test_mode = true
|
|
18
17
|
RSpec.configure do |config|
|
19
18
|
config.use_transactional_fixtures = true
|
20
19
|
config.infer_base_class_for_anonymous_controllers = false
|
21
|
-
|
22
|
-
config.include OpenSesame::Github::Capybara, :type => :request
|
23
20
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
|
3
|
+
module CapybaraHelper
|
4
|
+
|
5
|
+
def setup_for_github_login(user = test_user)
|
6
|
+
OmniAuth.config.mock_auth[:github] = {
|
7
|
+
"provider" => 'github',
|
8
|
+
"uid" => test_user.id
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_user
|
13
|
+
Octokit.user('rossta')
|
14
|
+
end
|
15
|
+
|
16
|
+
def login_with_github
|
17
|
+
setup_for_github_login
|
18
|
+
visit root_path
|
19
|
+
click_link 'github'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
RSpec.configuration.send :include, CapybaraHelper, :type => :request
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# courtesy of hassox/warden
|
4
|
+
require 'rack'
|
5
|
+
|
6
|
+
module RequestHelpers
|
7
|
+
FAILURE_APP = lambda{|e|[401, {"Content-Type" => "text/plain"}, ["You Fail!"]] }
|
8
|
+
|
9
|
+
def env_with_params(path = "/", params = {}, env = {})
|
10
|
+
method = params.delete(:method) || "GET"
|
11
|
+
env = { 'HTTP_VERSION' => '1.1', 'REQUEST_METHOD' => "#{method}" }.merge(env)
|
12
|
+
Rack::MockRequest.env_for("#{path}?#{Rack::Utils.build_query(params)}", env)
|
13
|
+
end
|
14
|
+
|
15
|
+
def env_with_rack_session(path = "/", params = {}, env = {})
|
16
|
+
env_with_params(path, params, env).tap do |rack_env|
|
17
|
+
rack_env['rack.session'] ||= {}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup_rack(app = nil, opts = {}, &block)
|
22
|
+
app ||= block if block_given?
|
23
|
+
|
24
|
+
opts[:failure_app] ||= failure_app
|
25
|
+
opts[:default_strategies] ||= [:password]
|
26
|
+
opts[:default_serializers] ||= [:session]
|
27
|
+
blk = opts[:configurator] || proc{}
|
28
|
+
|
29
|
+
Rack::Builder.new do
|
30
|
+
use opts[:session] || Warden::Spec::Helpers::Session
|
31
|
+
use Warden::Manager, opts, &blk
|
32
|
+
run app
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def valid_response
|
37
|
+
Rack::Response.new("OK").finish
|
38
|
+
end
|
39
|
+
|
40
|
+
def failure_app
|
41
|
+
FAILURE_APP
|
42
|
+
end
|
43
|
+
|
44
|
+
def success_app
|
45
|
+
lambda{|e| [200, {"Content-Type" => "text/plain"}, ["You Win"]]}
|
46
|
+
end
|
47
|
+
|
48
|
+
class Session
|
49
|
+
attr_accessor :app
|
50
|
+
def initialize(app, configs = {})
|
51
|
+
@app = app
|
52
|
+
end
|
53
|
+
|
54
|
+
def call(e)
|
55
|
+
e['rack.session'] ||= {}
|
56
|
+
@app.call(e)
|
57
|
+
end
|
58
|
+
end # session
|
59
|
+
end
|
60
|
+
|
61
|
+
RSpec.configuration.send(:include, RequestHelpers)
|
data/spec/support/vcr.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'vcr'
|
3
|
+
require 'fakeweb'
|
4
|
+
|
5
|
+
VCR.configure do |c|
|
6
|
+
c.cassette_library_dir = 'spec/vcr'
|
7
|
+
c.allow_http_connections_when_no_cassette = true
|
8
|
+
c.hook_into :fakeweb
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec.configure do |c|
|
12
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
c.around(:each, :vcr) do |example|
|
14
|
+
name = example.metadata[:cassette]
|
15
|
+
unless name
|
16
|
+
namespace = example.metadata[:full_description].split.first.split("::").last.downcase
|
17
|
+
spec_name = example.metadata[:description].split.join("_")
|
18
|
+
name = [namespace, spec_name].join("/")
|
19
|
+
end
|
20
|
+
VCR.use_cassette(name, :record => example.metadata[:record]) { example.call }
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
recorded_with: VCR 2.2.4
|
3
|
+
http_interactions:
|
4
|
+
- request:
|
5
|
+
method: get
|
6
|
+
uri: https://api.github.com/orgs/challengepost/members
|
7
|
+
body:
|
8
|
+
string: ""
|
9
|
+
headers:
|
10
|
+
accept:
|
11
|
+
- "*/*"
|
12
|
+
response:
|
13
|
+
status:
|
14
|
+
code: 200
|
15
|
+
message: OK
|
16
|
+
headers:
|
17
|
+
x-content-type-options:
|
18
|
+
- nosniff
|
19
|
+
etag:
|
20
|
+
- "\"a15607b962c849a75315fa5d68d6c4bb\""
|
21
|
+
x-ratelimit-limit:
|
22
|
+
- "5000"
|
23
|
+
last-modified:
|
24
|
+
- Tue, 21 Aug 2012 18:19:04 GMT
|
25
|
+
connection:
|
26
|
+
- close
|
27
|
+
content-type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
date:
|
30
|
+
- Tue, 21 Aug 2012 20:22:32 GMT
|
31
|
+
server:
|
32
|
+
- nginx/1.0.13
|
33
|
+
x-ratelimit-remaining:
|
34
|
+
- "4999"
|
35
|
+
content-length:
|
36
|
+
- "4444"
|
37
|
+
vary:
|
38
|
+
- Accept
|
39
|
+
cache-control:
|
40
|
+
- public, max-age=60, s-maxage=60
|
41
|
+
status:
|
42
|
+
- 200 OK
|
43
|
+
body:
|
44
|
+
string: "[{\"gravatar_id\":\"f009205a899da22248cca0b772aec9c9\",\"login\":\"bkessler\",\"avatar_url\":\"https://secure.gravatar.com/avatar/f009205a899da22248cca0b772aec9c9?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/bkessler\",\"id\":1533742},{\"gravatar_id\":\"8fbb8f95c839dd7fcda64484b13fb6d2\",\"login\":\"bkoles\",\"avatar_url\":\"https://secure.gravatar.com/avatar/8fbb8f95c839dd7fcda64484b13fb6d2?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/bkoles\",\"id\":1520717},{\"gravatar_id\":\"5ca79e98b58912c64c025abf2c22d191\",\"login\":\"coldjuly\",\"avatar_url\":\"https://secure.gravatar.com/avatar/5ca79e98b58912c64c025abf2c22d191?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/coldjuly\",\"id\":607567},{\"gravatar_id\":\"30e9b9399e2550faf840e5be21899c84\",\"login\":\"holly12\",\"avatar_url\":\"https://secure.gravatar.com/avatar/30e9b9399e2550faf840e5be21899c84?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/holly12\",\"id\":482730},{\"gravatar_id\":\"ed957dc9ac370af026f758357bfdc314\",\"login\":\"ilyakatz\",\"avatar_url\":\"https://secure.gravatar.com/avatar/ed957dc9ac370af026f758357bfdc314?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/ilyakatz\",\"id\":282514},{\"gravatar_id\":\"2d20d0edc591c7e4524dd7e2e1a91b96\",\"login\":\"jcmuller\",\"avatar_url\":\"https://secure.gravatar.com/avatar/2d20d0edc591c7e4524dd7e2e1a91b96?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/jcmuller\",\"id\":208500},{\"gravatar_id\":\"49cc454955e9dd99561edf64b8624557\",\"login\":\"marend\",\"avatar_url\":\"https://secure.gravatar.com/avatar/49cc454955e9dd99561edf64b8624557?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/marend\",\"id\":1799340},{\"gravatar_id\":\"c0f5a8a1b1c54a4d471b0bb38bf3def7\",\"login\":\"marnysmith\",\"avatar_url\":\"https://secure.gravatar.com/avatar/c0f5a8a1b1c54a4d471b0bb38bf3def7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/marnysmith\",\"id\":699974},{\"gravatar_id\":\"29941743a06edc8ac198ef8cef8e8eeb\",\"login\":\"midu\",\"avatar_url\":\"https://secure.gravatar.com/avatar/29941743a06edc8ac198ef8cef8e8eeb?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/midu\",\"id\":188390},{\"gravatar_id\":\"17dd146c6ef6acc844501945bf2fe6f2\",\"login\":\"mtully\",\"avatar_url\":\"https://secure.gravatar.com/avatar/17dd146c6ef6acc844501945bf2fe6f2?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/mtully\",\"id\":129630},{\"gravatar_id\":\"d43dc36474bd0a252ed907d46511ded7\",\"login\":\"niuage\",\"avatar_url\":\"https://secure.gravatar.com/avatar/d43dc36474bd0a252ed907d46511ded7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/niuage\",\"id\":208622},{\"gravatar_id\":\"f2280a3b4988d3635e62c9634ef9ce1a\",\"login\":\"pjrobinson\",\"avatar_url\":\"https://secure.gravatar.com/avatar/f2280a3b4988d3635e62c9634ef9ce1a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/pjrobinson\",\"id\":1612903},{\"gravatar_id\":\"e117a79e0e2b4bc4b3464803bde9d60c\",\"login\":\"returntrue\",\"avatar_url\":\"https://secure.gravatar.com/avatar/e117a79e0e2b4bc4b3464803bde9d60c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/returntrue\",\"id\":593172},{\"gravatar_id\":\"b0169a78f851962058d63337ad0147d6\",\"login\":\"rossta\",\"avatar_url\":\"https://secure.gravatar.com/avatar/b0169a78f851962058d63337ad0147d6?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/rossta\",\"id\":11673},{\"gravatar_id\":\"193f23d2369d96b67c2e4de772083c8c\",\"login\":\"Serena101\",\"avatar_url\":\"https://secure.gravatar.com/avatar/193f23d2369d96b67c2e4de772083c8c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"url\":\"https://api.github.com/users/Serena101\",\"id\":1815937}]"
|
45
|
+
http_version: "1.1"
|
46
|
+
recorded_at: Tue, 21 Aug 2012 20:22:32 GMT
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
recorded_with: VCR 2.2.4
|
3
|
+
http_interactions:
|
4
|
+
- request:
|
5
|
+
method: get
|
6
|
+
uri: https://api.github.com/orgs/challengepost/members
|
7
|
+
body:
|
8
|
+
string: ""
|
9
|
+
headers:
|
10
|
+
accept:
|
11
|
+
- "*/*"
|
12
|
+
response:
|
13
|
+
status:
|
14
|
+
code: 200
|
15
|
+
message: OK
|
16
|
+
headers:
|
17
|
+
x-content-type-options:
|
18
|
+
- nosniff
|
19
|
+
etag:
|
20
|
+
- "\"a15607b962c849a75315fa5d68d6c4bb\""
|
21
|
+
x-ratelimit-limit:
|
22
|
+
- "5000"
|
23
|
+
last-modified:
|
24
|
+
- Tue, 21 Aug 2012 18:19:04 GMT
|
25
|
+
connection:
|
26
|
+
- close
|
27
|
+
content-type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
date:
|
30
|
+
- Tue, 21 Aug 2012 20:22:32 GMT
|
31
|
+
server:
|
32
|
+
- nginx/1.0.13
|
33
|
+
x-ratelimit-remaining:
|
34
|
+
- "4998"
|
35
|
+
content-length:
|
36
|
+
- "4444"
|
37
|
+
cache-control:
|
38
|
+
- public, max-age=60, s-maxage=60
|
39
|
+
vary:
|
40
|
+
- Accept
|
41
|
+
status:
|
42
|
+
- 200 OK
|
43
|
+
body:
|
44
|
+
string: "[{\"avatar_url\":\"https://secure.gravatar.com/avatar/f009205a899da22248cca0b772aec9c9?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"f009205a899da22248cca0b772aec9c9\",\"login\":\"bkessler\",\"url\":\"https://api.github.com/users/bkessler\",\"id\":1533742},{\"avatar_url\":\"https://secure.gravatar.com/avatar/8fbb8f95c839dd7fcda64484b13fb6d2?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"8fbb8f95c839dd7fcda64484b13fb6d2\",\"login\":\"bkoles\",\"url\":\"https://api.github.com/users/bkoles\",\"id\":1520717},{\"avatar_url\":\"https://secure.gravatar.com/avatar/5ca79e98b58912c64c025abf2c22d191?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"5ca79e98b58912c64c025abf2c22d191\",\"login\":\"coldjuly\",\"url\":\"https://api.github.com/users/coldjuly\",\"id\":607567},{\"avatar_url\":\"https://secure.gravatar.com/avatar/30e9b9399e2550faf840e5be21899c84?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"30e9b9399e2550faf840e5be21899c84\",\"login\":\"holly12\",\"url\":\"https://api.github.com/users/holly12\",\"id\":482730},{\"avatar_url\":\"https://secure.gravatar.com/avatar/ed957dc9ac370af026f758357bfdc314?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"ed957dc9ac370af026f758357bfdc314\",\"login\":\"ilyakatz\",\"url\":\"https://api.github.com/users/ilyakatz\",\"id\":282514},{\"avatar_url\":\"https://secure.gravatar.com/avatar/2d20d0edc591c7e4524dd7e2e1a91b96?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"2d20d0edc591c7e4524dd7e2e1a91b96\",\"login\":\"jcmuller\",\"url\":\"https://api.github.com/users/jcmuller\",\"id\":208500},{\"avatar_url\":\"https://secure.gravatar.com/avatar/49cc454955e9dd99561edf64b8624557?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"49cc454955e9dd99561edf64b8624557\",\"login\":\"marend\",\"url\":\"https://api.github.com/users/marend\",\"id\":1799340},{\"avatar_url\":\"https://secure.gravatar.com/avatar/c0f5a8a1b1c54a4d471b0bb38bf3def7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"c0f5a8a1b1c54a4d471b0bb38bf3def7\",\"login\":\"marnysmith\",\"url\":\"https://api.github.com/users/marnysmith\",\"id\":699974},{\"avatar_url\":\"https://secure.gravatar.com/avatar/29941743a06edc8ac198ef8cef8e8eeb?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"29941743a06edc8ac198ef8cef8e8eeb\",\"login\":\"midu\",\"url\":\"https://api.github.com/users/midu\",\"id\":188390},{\"avatar_url\":\"https://secure.gravatar.com/avatar/17dd146c6ef6acc844501945bf2fe6f2?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"17dd146c6ef6acc844501945bf2fe6f2\",\"login\":\"mtully\",\"url\":\"https://api.github.com/users/mtully\",\"id\":129630},{\"avatar_url\":\"https://secure.gravatar.com/avatar/d43dc36474bd0a252ed907d46511ded7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"d43dc36474bd0a252ed907d46511ded7\",\"login\":\"niuage\",\"url\":\"https://api.github.com/users/niuage\",\"id\":208622},{\"avatar_url\":\"https://secure.gravatar.com/avatar/f2280a3b4988d3635e62c9634ef9ce1a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"f2280a3b4988d3635e62c9634ef9ce1a\",\"login\":\"pjrobinson\",\"url\":\"https://api.github.com/users/pjrobinson\",\"id\":1612903},{\"avatar_url\":\"https://secure.gravatar.com/avatar/e117a79e0e2b4bc4b3464803bde9d60c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"e117a79e0e2b4bc4b3464803bde9d60c\",\"login\":\"returntrue\",\"url\":\"https://api.github.com/users/returntrue\",\"id\":593172},{\"avatar_url\":\"https://secure.gravatar.com/avatar/b0169a78f851962058d63337ad0147d6?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"b0169a78f851962058d63337ad0147d6\",\"login\":\"rossta\",\"url\":\"https://api.github.com/users/rossta\",\"id\":11673},{\"avatar_url\":\"https://secure.gravatar.com/avatar/193f23d2369d96b67c2e4de772083c8c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png\",\"gravatar_id\":\"193f23d2369d96b67c2e4de772083c8c\",\"login\":\"Serena101\",\"url\":\"https://api.github.com/users/Serena101\",\"id\":1815937}]"
|
45
|
+
http_version: "1.1"
|
46
|
+
recorded_at: Tue, 21 Aug 2012 20:22:32 GMT
|