currentuser-services 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/README.md +4 -4
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/app/controllers/currentuser/services/sessions_controller.rb +4 -2
- data/currentuser-services.gemspec +6 -4
- data/lib/currentuser/services/controllers/authenticates.rb +5 -1
- data/test/currentuser/services/authenticates_test.rb +16 -3
- data/test/currentuser/services/integration_test.rb +0 -7
- data/test/currentuser/services/sessions_controller_test.rb +90 -0
- data/test/helper.rb +9 -4
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27d69251789724bbec4043769a4ccb50dd11829e
|
4
|
+
data.tar.gz: 6367213142ff7f9d6aa4ad3e5cb5e852bfc857d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 831b8cd72a0f0fd91c5003a746a0a5fc56846dc6e6dd3ac2a41a8c7430e07b1d4abc7dac6cf176f28c37df410d55c1b97b424fd1ddd9ba16bce66bb84e0970d1
|
7
|
+
data.tar.gz: 58c9a09c718cbea0f0400be11486569064d9b7761f4a697586064665792fac1bd0444e2b4500148ae1d16c0ba8091e8f4a494fd26bdc9f57a6c644773d8001d6
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.2.0
|
4
|
+
|
5
|
+
**Feature**
|
6
|
+
|
7
|
+
* Set `:sign_up` context in session (undocumented because unreliable yet)
|
8
|
+
|
9
|
+
**Refactoring**
|
10
|
+
|
11
|
+
* Change the way currentuser data is stored in session
|
12
|
+
|
13
|
+
## 0.1.0
|
14
|
+
|
15
|
+
**Improvement**
|
16
|
+
|
17
|
+
* **[Breaking change]** Use HTTP DELETE rather than HTTP GET for sign out
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ end
|
|
32
32
|
|
33
33
|
## Usage
|
34
34
|
|
35
|
-
* Use `currentuser_sign_up_url
|
35
|
+
* Use `currentuser_sign_up_url` (GET), `currentuser_sign_in_url` (GET) and `currentuser_sign_out_url` (DELETE) in your navigation to allow
|
36
36
|
visitor to sign up, in and out
|
37
37
|
* Use `:require_currentuser` as `before_action` to protect your restricted actions
|
38
38
|
* In any action or view, you can use `currentuser_id` to retrieve the id of the connected user (if any)
|
@@ -84,13 +84,13 @@ end
|
|
84
84
|
```haml
|
85
85
|
-# views/shared/_menu.html.haml
|
86
86
|
%ul
|
87
|
+
%li
|
88
|
+
= link_to 'Home', :root
|
87
89
|
- if currentuser_id
|
88
|
-
%li
|
89
|
-
= link_to 'Home', :root
|
90
90
|
%li
|
91
91
|
= link_to 'Restricted', :restricted
|
92
92
|
%li
|
93
|
-
=
|
93
|
+
= button_to 'Sign out', currentuser_sign_out_url, method: :delete
|
94
94
|
- else
|
95
95
|
%li
|
96
96
|
= link_to 'Sign up', currentuser_sign_up_url
|
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ require 'jeweler'
|
|
15
15
|
Jeweler::Tasks.new do |gem|
|
16
16
|
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
17
|
gem.name = 'currentuser-services'
|
18
|
-
gem.homepage = 'http://
|
18
|
+
gem.homepage = 'http://www.currentuser.io'
|
19
19
|
gem.license = 'MIT'
|
20
20
|
gem.summary = %Q{Offsite sign up and sign in forms for Currentuser.io}
|
21
21
|
gem.description = %Q{Offsite sign up and sign in forms for Currentuser.io}
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -6,13 +6,15 @@ module Currentuser
|
|
6
6
|
Services.check_authentication_params!(params)
|
7
7
|
|
8
8
|
# Log in
|
9
|
-
session[:
|
9
|
+
session[:currentuser] = {id: params[:currentuser_id]}
|
10
|
+
# Note that params[:sign_up] should equal 'true' (String) or should be absent.
|
11
|
+
session[:currentuser][:sign_up] = true if params[:sign_up]
|
10
12
|
|
11
13
|
redirect_to '/'
|
12
14
|
end
|
13
15
|
|
14
16
|
def sign_out
|
15
|
-
session.delete(:
|
17
|
+
session.delete(:currentuser)
|
16
18
|
|
17
19
|
redirect_to '/'
|
18
20
|
end
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: currentuser-services 0.
|
5
|
+
# stub: currentuser-services 0.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "currentuser-services"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["eric-currentuser"]
|
14
|
-
s.date = "2014-12-
|
14
|
+
s.date = "2014-12-27"
|
15
15
|
s.description = "Offsite sign up and sign in forms for Currentuser.io"
|
16
16
|
s.email = "TBD"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
]
|
21
21
|
s.files = [
|
22
22
|
".document",
|
23
|
+
"CHANGELOG.md",
|
23
24
|
"Gemfile",
|
24
25
|
"LICENSE.txt",
|
25
26
|
"README.md",
|
@@ -34,11 +35,12 @@ Gem::Specification.new do |s|
|
|
34
35
|
"lib/currentuser/services/engine.rb",
|
35
36
|
"test/currentuser/services/authenticates_test.rb",
|
36
37
|
"test/currentuser/services/integration_test.rb",
|
38
|
+
"test/currentuser/services/sessions_controller_test.rb",
|
37
39
|
"test/currentuser/services_test.rb",
|
38
40
|
"test/helper.rb",
|
39
41
|
"test/test_application/application.rb"
|
40
42
|
]
|
41
|
-
s.homepage = "http://
|
43
|
+
s.homepage = "http://www.currentuser.io"
|
42
44
|
s.licenses = ["MIT"]
|
43
45
|
s.rubygems_version = "2.2.2"
|
44
46
|
s.summary = "Offsite sign up and sign in forms for Currentuser.io"
|
@@ -6,8 +6,12 @@ module Currentuser
|
|
6
6
|
redirect_to currentuser_sign_in_url
|
7
7
|
end
|
8
8
|
|
9
|
+
def currentuser_session
|
10
|
+
return session[:currentuser]
|
11
|
+
end
|
12
|
+
|
9
13
|
def currentuser_id
|
10
|
-
return @currentuser_id ||=
|
14
|
+
return @currentuser_id ||= currentuser_session && currentuser_session[:id]
|
11
15
|
end
|
12
16
|
|
13
17
|
def currentuser_sign_in_url
|
@@ -30,28 +30,41 @@ module Currentuser
|
|
30
30
|
# require_currentuser
|
31
31
|
|
32
32
|
test 'execute action if currentuser_id is available' do
|
33
|
-
session[:
|
33
|
+
session[:currentuser] = {id: 'user_id_1'}
|
34
34
|
|
35
35
|
get_with_route :test_action_requiring_user
|
36
36
|
assert_response :ok
|
37
37
|
end
|
38
38
|
|
39
39
|
test 'redirects to sign_in URL if currentuser_id is not available' do
|
40
|
-
assert_nil session[:
|
40
|
+
assert_nil session[:currentuser]
|
41
41
|
|
42
42
|
get_with_route :test_action_requiring_user
|
43
43
|
assert_response :redirect
|
44
44
|
assert_redirected_to Services.currentuser_url(:sign_in)
|
45
45
|
end
|
46
46
|
|
47
|
+
# currentuser_session
|
48
|
+
|
49
|
+
test 'currentuser_session returns currentuser session' do
|
50
|
+
session[:currentuser] = {foo: 'blah'}
|
51
|
+
|
52
|
+
assert_equal({foo: 'blah'}, @controller.currentuser_session)
|
53
|
+
end
|
54
|
+
|
47
55
|
# currentuser_id
|
48
56
|
|
49
57
|
test 'currentuser_id returns currentuser ID' do
|
50
|
-
session[:
|
58
|
+
session[:currentuser] = {id: 'user_id_1'}
|
51
59
|
|
52
60
|
assert_equal 'user_id_1', @controller.currentuser_id
|
53
61
|
end
|
54
62
|
|
63
|
+
test 'currentuser_id returns nil if no current user session' do
|
64
|
+
refute session.key?(:currentuser)
|
65
|
+
assert_nil @controller.currentuser_id
|
66
|
+
end
|
67
|
+
|
55
68
|
# sign_in_url
|
56
69
|
|
57
70
|
test 'sign_in_url returns the expected url' do
|
@@ -10,16 +10,9 @@ require 'test_application/application'
|
|
10
10
|
require 'minitest/rails/capybara'
|
11
11
|
require 'capybara/mechanize'
|
12
12
|
|
13
|
-
require 'currentuser/data'
|
14
|
-
require 'currentuser/data/test/helpers'
|
15
|
-
|
16
13
|
#Rails.logger = Logger.new(STDOUT)
|
17
14
|
Rails.logger = Logger.new('/dev/null')
|
18
15
|
|
19
|
-
Currentuser::Data::BaseResource.site = ENV['CURRENTUSER_DATA_URL']
|
20
|
-
Currentuser::Data::Test::UseReadApi.currentuser_project_id_for_tests =
|
21
|
-
Currentuser::Services.configuration.project_id
|
22
|
-
|
23
16
|
module Currentuser
|
24
17
|
module Services
|
25
18
|
Capybara.current_driver = :mechanize
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Currentuser
|
4
|
+
module Services
|
5
|
+
|
6
|
+
class SessionsControllerTest < ActionController::TestCase
|
7
|
+
tests SessionsController
|
8
|
+
|
9
|
+
def process_with_route(verb, action, params, session={})
|
10
|
+
with_routing do |map|
|
11
|
+
map.draw do
|
12
|
+
currentuser
|
13
|
+
end
|
14
|
+
send verb, action, params.merge(use_route: 'currentuser/services'), session
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_with_route(action, params={})
|
19
|
+
process_with_route :get, action, params
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete_with_route(action, params, session)
|
23
|
+
process_with_route :delete, action, params, session
|
24
|
+
end
|
25
|
+
|
26
|
+
# sign_in
|
27
|
+
|
28
|
+
test 'sign_in logs user in and redirects to root' do
|
29
|
+
|
30
|
+
# Take a recent timestamp
|
31
|
+
timestamp = (Time.now - 60).to_i.to_s
|
32
|
+
user_id = 'user_id_1'
|
33
|
+
|
34
|
+
# By pass signature checking
|
35
|
+
Services.stub :signature_authentic?, true do
|
36
|
+
get_with_route :sign_in, currentuser_id: user_id, timestamp: timestamp, signature: 'any_signature'
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_redirected_to '/'
|
40
|
+
assert_equal({id: user_id}, session[:currentuser])
|
41
|
+
refute session[:currentuser].has_key?(:sign_up)
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'sign_in sets sign_up if sign_up is true' do
|
45
|
+
|
46
|
+
# Take a recent timestamp
|
47
|
+
timestamp = (Time.now - 60).to_i.to_s
|
48
|
+
|
49
|
+
# By pass signature checking
|
50
|
+
Services.stub :signature_authentic?, true do
|
51
|
+
get_with_route :sign_in, currentuser_id: 'user_id_1', timestamp: timestamp, signature: 'any_signature',
|
52
|
+
sign_up: 'true'
|
53
|
+
end
|
54
|
+
|
55
|
+
assert_redirected_to '/'
|
56
|
+
assert_equal true, session[:currentuser][:sign_up]
|
57
|
+
end
|
58
|
+
|
59
|
+
# This test proves that we use Services#check_authentication_params!
|
60
|
+
test 'sign_in raises SignatureNotAuthentic if signature is wrong' do
|
61
|
+
# Take a recent timestamp
|
62
|
+
timestamp = (Time.now - 60).to_i.to_s
|
63
|
+
|
64
|
+
assert_raises SignatureNotAuthentic do
|
65
|
+
get_with_route :sign_in, currentuser_id: 'user_id_1', timestamp: timestamp, signature: 'any_signature'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# sign_out
|
70
|
+
|
71
|
+
test 'sign_out deletes session and redirects to root' do
|
72
|
+
session_hash = {currentuser: {foo: :blah}, other_key: :other_value}
|
73
|
+
|
74
|
+
delete_with_route :sign_out, {}, session_hash
|
75
|
+
assert_redirected_to '/'
|
76
|
+
|
77
|
+
assert_nil session[:currentuser]
|
78
|
+
assert_equal :other_value, session[:other_key]
|
79
|
+
end
|
80
|
+
|
81
|
+
# available
|
82
|
+
|
83
|
+
test 'GET available return 300' do
|
84
|
+
get_with_route 'available'
|
85
|
+
assert_response :ok
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/test/helper.rb
CHANGED
@@ -11,16 +11,21 @@ require 'action_controller'
|
|
11
11
|
require 'dotenv'
|
12
12
|
Dotenv.load
|
13
13
|
|
14
|
+
# Load and configure this gem (currentuser-services)
|
14
15
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
15
16
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'app'))
|
16
17
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
17
18
|
require 'currentuser/services'
|
18
|
-
|
19
19
|
Currentuser::Services.configure do |config|
|
20
20
|
config.project_id = ENV['CURRENTUSER_PROJECT_ID_FOR_TESTS']
|
21
|
-
end
|
22
|
-
|
23
|
-
Currentuser::Services.configure do |config|
|
24
21
|
config.currentuser_services_host = ENV['CURRENTUSER_SERVICES_HOST']
|
25
22
|
config.currentuser_services_public_key = ENV['CURRENTUSER_SERVICES_PUBLIC_KEY']
|
26
23
|
end
|
24
|
+
|
25
|
+
# Load and configure 'currentuser-data' for tests.
|
26
|
+
# Note this is required only in 'integration_test.rb'.
|
27
|
+
require 'currentuser/data'
|
28
|
+
require 'currentuser/data/test/helpers'
|
29
|
+
Currentuser::Data::BaseResource.site = ENV['CURRENTUSER_DATA_URL']
|
30
|
+
Currentuser::Data::Test::UseReadApi.currentuser_project_id_for_tests =
|
31
|
+
Currentuser::Services.configuration.project_id
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: currentuser-services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- eric-currentuser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_config
|
@@ -173,6 +173,7 @@ extra_rdoc_files:
|
|
173
173
|
- README.md
|
174
174
|
files:
|
175
175
|
- .document
|
176
|
+
- CHANGELOG.md
|
176
177
|
- Gemfile
|
177
178
|
- LICENSE.txt
|
178
179
|
- README.md
|
@@ -187,10 +188,11 @@ files:
|
|
187
188
|
- lib/currentuser/services/engine.rb
|
188
189
|
- test/currentuser/services/authenticates_test.rb
|
189
190
|
- test/currentuser/services/integration_test.rb
|
191
|
+
- test/currentuser/services/sessions_controller_test.rb
|
190
192
|
- test/currentuser/services_test.rb
|
191
193
|
- test/helper.rb
|
192
194
|
- test/test_application/application.rb
|
193
|
-
homepage: http://
|
195
|
+
homepage: http://www.currentuser.io
|
194
196
|
licenses:
|
195
197
|
- MIT
|
196
198
|
metadata: {}
|