rom-auth 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,68 @@
1
+ describe ROM::Auth::System do
2
+
3
+ let(:setup) { ROM.setup(:sql, "sqlite::memory") }
4
+ let(:connection) { setup.default.connection }
5
+
6
+ def password
7
+ 'somepassword'
8
+ end
9
+
10
+ def password_verifier
11
+ ROM::Auth::PasswordVerifiers::PBKDF2Verifier.for_password(password)
12
+ end
13
+
14
+ before do
15
+ connection.create_table(:users) do
16
+ primary_key :id
17
+ end
18
+
19
+ class User
20
+ include Virtus.value_object(coerce: false)
21
+
22
+ values do
23
+ attribute :id, Integer
24
+ end
25
+ end
26
+
27
+ @users = Class.new(ROM::Relation[:sql]) do
28
+ register_as :users
29
+ dataset :users
30
+
31
+ def by_id(id)
32
+ where(id: id)
33
+ end
34
+ end
35
+
36
+ @mapper = Class.new(ROM::Mapper) do
37
+ relation(:users)
38
+ model(User) # FIXME
39
+ end
40
+ end
41
+
42
+ it '#authenticate' do
43
+ config = ROM::Auth::Configuration.new do |c|
44
+ c.plugin(ROM::Auth::Plugins::AuthenticationCredentialsPlugin)
45
+ end
46
+
47
+ system = ROM::Auth::System.new(config)
48
+
49
+ system.migrate!(setup)
50
+
51
+ rom = ROM.finalize.env
52
+
53
+ expect{ system.authenticate(nil) }.to raise_error
54
+
55
+ connection[:users].insert(id: 1)
56
+ connection[:authentication_credentials].insert(
57
+ user_id: 1,
58
+ type: 'email',
59
+ identifier: 'a@b.c.de',
60
+ verifier_data: password_verifier.to_s
61
+ )
62
+
63
+ creds = OpenStruct.new(identifier: 'a@b.c.de', type: 'email', password: password)
64
+
65
+ assert{ system.authenticate(creds) }
66
+ end
67
+
68
+ end
@@ -0,0 +1,27 @@
1
+ describe ROM::Auth::Configuration do
2
+ it '' do
3
+ config = described_class.new do
4
+ end
5
+
6
+ assert{ config.plugins == {} }
7
+ end
8
+
9
+ it '' do
10
+ config = described_class.new do |c|
11
+ c.plugin ROM::Auth::Plugins::AuthenticationEventsPlugin
12
+ end
13
+
14
+ assert{ config.plugins.keys == [ROM::Auth::Plugins::AuthenticationEventsPlugin] }
15
+ end
16
+
17
+ it '' do
18
+ config = described_class.new do |c|
19
+ c.plugin ROM::Auth::Plugins::AuthenticationEventsPlugin do
20
+ end
21
+ end
22
+
23
+ plugin_data = config.plugins[ROM::Auth::Plugins::AuthenticationEventsPlugin]
24
+
25
+ assert{ plugin_data.is_a?(ROM::Auth::Plugins::AuthenticationEventsPlugin::Configuration) }
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ describe ROM::Auth::PasswordVerifiers::PBKDF2Verifier do
2
+
3
+ let(:password) { 'somelongpw123,.-' }
4
+ let(:salt) { 'AAFF435' }
5
+ let(:verifier) { described_class.for_password(password, :salt => salt, :iterations => 2) }
6
+
7
+ describe '#initialize' do
8
+ it { assert{ verifier.class == ROM::Auth::PasswordVerifiers::PBKDF2Verifier } }
9
+ it { assert{ verifier.salt == salt } }
10
+ it { assert{ verifier.digest.is_a?(ROM::Auth::Digest) } }
11
+ it { assert{ verifier.digest.to_s == PBKDF2.new(:password => password, :salt => salt, :iterations => 2).hex_string } }
12
+ end
13
+
14
+ describe '#verifies' do
15
+ it { assert{ verifier.verifies?(password) } }
16
+ it { assert{ !verifier.verifies?('incorrect password') } }
17
+ it { assert{ !verifier.verifies?('') } }
18
+ end
19
+
20
+ describe '#to_s' do
21
+ it { assert{ verifier.to_s == "PBKDF2,#{salt},#{verifier.digest},2" } }
22
+ end
23
+
24
+ describe '.from_s' do
25
+ it { assert{ described_class.from_s(verifier.to_s) == verifier } }
26
+ it { assert{ described_class.from_s(verifier.to_s).to_s == verifier.to_s } }
27
+ it { assert{ described_class.from_s(verifier.to_s).verifies?(password) } }
28
+ end
29
+
30
+ end
@@ -0,0 +1,109 @@
1
+ describe ROM::Auth::Plugins::AuthenticationEventsPlugin do
2
+ let(:setup) { ROM.setup(:sql, "sqlite::memory") }
3
+ let(:connection) { setup.default.connection }
4
+
5
+ def password
6
+ 'somepassword'
7
+ end
8
+
9
+ def password_verifier
10
+ ROM::Auth::PasswordVerifiers::PBKDF2Verifier.for_password(password)
11
+ end
12
+
13
+ it '#configure plugin' do
14
+ config = ROM::Auth::Configuration.new do |c|
15
+ c.plugin(described_class) do |c|
16
+ c.table_name = 'lolerskates'
17
+ end
18
+ end
19
+
20
+ system = ROM::Auth::System.new(config)
21
+
22
+ assert{ system.plugins.keys == [described_class] }
23
+ assert{ system.plugins[described_class].configuration.table_name == :lolerskates }
24
+ end
25
+
26
+ it '#migrate' do
27
+ config = ROM::Auth::Configuration.new do |c|
28
+ c.plugin(described_class) do |c|
29
+ c.table_name = 'lolerskates'
30
+ end
31
+ end
32
+
33
+ system = ROM::Auth::System.new(config)
34
+ system.migrate!(setup)
35
+
36
+ ROM.finalize
37
+
38
+ assert{
39
+ setup.default.connection.schema(:lolerskates).map{|c| c.first} == [
40
+ :id, :user_id, :started_at, :ended_at,
41
+ :identifier, :type, :authenticated, :success, :data
42
+ ]
43
+ }
44
+ end
45
+
46
+ it 'ROM::Auth::System#authenticate' do
47
+ config = ROM::Auth::Configuration.new do |c|
48
+ c.plugin(ROM::Auth::Plugins::AuthenticationCredentialsPlugin) do
49
+ end
50
+
51
+ c.plugin(described_class) do |c|
52
+ c.table_name = :auth_events
53
+ end
54
+ end
55
+
56
+ class User
57
+ include Virtus.value_object(coerce: false)
58
+
59
+ values do
60
+ attribute :id, Integer
61
+ end
62
+ end
63
+
64
+ connection.create_table(:users) do
65
+ primary_key :id
66
+ end
67
+
68
+ @users = Class.new(ROM::Relation[:sql]) do
69
+ dataset :users
70
+
71
+ def by_id(id)
72
+ where(id: id)
73
+ end
74
+ end
75
+
76
+ @mapper = Class.new(ROM::Mapper) do
77
+ relation(:users)
78
+ model(User) # FIXME
79
+ end
80
+
81
+ system = ROM::Auth::System.new(config)
82
+ system.migrate!(setup)
83
+
84
+ rom = ROM.finalize.env
85
+
86
+ connection[:users].insert(id: 1)
87
+ connection[:authentication_credentials].insert(
88
+ user_id: 1,
89
+ type: 'email',
90
+ identifier: 'a@b.c.de',
91
+ verifier_data: password_verifier.to_s
92
+ )
93
+
94
+ credentials = double(type: 'email', identifier: 'a@b.c.de', password: password)
95
+ user = double(:user, id: 1, password_verifier: password_verifier)
96
+
97
+ auths = rom.relation(:auth_events)
98
+
99
+ assert{ system.authenticate(credentials) }
100
+ assert{ auths.relation.count == 1 }
101
+
102
+ event = auths.as(:rom_auth_event).first
103
+ assert{ event.type == 'email' }
104
+ assert{ event.authenticated == true }
105
+ assert{ event.success == true }
106
+ assert{ event.user_id == 1 }
107
+ end
108
+
109
+ end
@@ -0,0 +1,3 @@
1
+ describe ROM::Auth do
2
+
3
+ end
metadata ADDED
@@ -0,0 +1,242 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rom-auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Ragmaanir
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rom
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rom-sql
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: virtus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ice_nine
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.11'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.11'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pbkdf2-ruby
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.2.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.2.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: wrong
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.7'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.7'
139
+ - !ruby/object:Gem::Dependency
140
+ name: minitest-stub-const
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.3'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.3'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.9'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.9'
167
+ - !ruby/object:Gem::Dependency
168
+ name: binding_of_caller
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.7'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '0.7'
181
+ description: Provides low-level authentication based on ROM. Provides several plugins
182
+ in order to lockdown accounts on failed authentication and saving events for each
183
+ authentication attempt.
184
+ email:
185
+ - ragmaanir@gmail.com
186
+ executables: []
187
+ extensions: []
188
+ extra_rdoc_files: []
189
+ files:
190
+ - README.md
191
+ - lib/rom-auth.rb
192
+ - lib/rom/auth.rb
193
+ - lib/rom/auth/authenticators/authenticator.rb
194
+ - lib/rom/auth/authenticators/password_authenticator.rb
195
+ - lib/rom/auth/configuration.rb
196
+ - lib/rom/auth/digest.rb
197
+ - lib/rom/auth/migration.rb
198
+ - lib/rom/auth/password_verifiers/password_verifier.rb
199
+ - lib/rom/auth/password_verifiers/pbkdf2_verifier.rb
200
+ - lib/rom/auth/plugins/authentication_credentials_plugin.rb
201
+ - lib/rom/auth/plugins/authentication_events_plugin.rb
202
+ - lib/rom/auth/plugins/lockdown_plugin.rb
203
+ - lib/rom/auth/plugins/plugin.rb
204
+ - lib/rom/auth/support/shorthand_symbol.rb
205
+ - lib/rom/auth/system.rb
206
+ - lib/rom/auth/version.rb
207
+ - spec/integration/common_plugins_spec.rb
208
+ - spec/integration/system_spec.rb
209
+ - spec/unit/rom/auth/configuration_spec.rb
210
+ - spec/unit/rom/auth/password_verifiers/pbkdf2_verifier_spec.rb
211
+ - spec/unit/rom/auth/plugins/authentication_events_plugin_spec.rb
212
+ - spec/unit/rom/auth_spec.rb
213
+ homepage: http://github.com/ragmaanir/rom-auth
214
+ licenses: []
215
+ metadata: {}
216
+ post_install_message:
217
+ rdoc_options: []
218
+ require_paths:
219
+ - lib
220
+ required_ruby_version: !ruby/object:Gem::Requirement
221
+ requirements:
222
+ - - "~>"
223
+ - !ruby/object:Gem::Version
224
+ version: '2.1'
225
+ required_rubygems_version: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '2.2'
230
+ requirements: []
231
+ rubyforge_project: rom-auth
232
+ rubygems_version: 2.4.5
233
+ signing_key:
234
+ specification_version: 4
235
+ summary: Simple web-framework independent authentication solution using ROM
236
+ test_files:
237
+ - spec/integration/common_plugins_spec.rb
238
+ - spec/integration/system_spec.rb
239
+ - spec/unit/rom/auth_spec.rb
240
+ - spec/unit/rom/auth/password_verifiers/pbkdf2_verifier_spec.rb
241
+ - spec/unit/rom/auth/configuration_spec.rb
242
+ - spec/unit/rom/auth/plugins/authentication_events_plugin_spec.rb