tuwien_logon 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -4,13 +4,15 @@ module TuwienLogon
4
4
  class Configuration
5
5
  include Singleton
6
6
 
7
- attr_accessor :authentication_url, :user_info_url, :secret, :user_info_params
7
+ attr_accessor :authentication_url, :user_info_url, :secret, :user_info_params, :time_tolerance, :server_time_offset
8
8
 
9
9
  def initialize
10
10
  @authentication_url = 'https://iu.zid.tuwien.ac.at/AuthServ.authenticate'
11
11
  @user_info_url = 'https://iu.zid.tuwien.ac.at/AuthServ.userInfo'
12
12
  @secret = '123456'
13
13
  @user_info_params = [:oid, :firstname, :lastname, :title, :matriculation_number, :institute_symbol]
14
+ @time_tolerance = 5
15
+ @server_time_offset = 0
14
16
  end
15
17
  end
16
18
  end
@@ -0,0 +1,101 @@
1
+ require 'helper'
2
+ require 'tuwien_logon/authentication'
3
+
4
+ class TestAuthentication < Test::Unit::TestCase
5
+ include TuwienLogon::Authentication
6
+
7
+ context 'The authentication' do
8
+ setup do
9
+ @time = Time.now
10
+ @authentication = Authentication.new 1, 'client', 'secret', 0, @time
11
+ end
12
+
13
+ should 'generate the correct skey' do
14
+ assert_equal correct_key(@authentication, @time), @authentication.skey
15
+ end
16
+
17
+ should 'generate the incorrect skey' do
18
+ key = Digest::SHA1.hexdigest("1clientsecret")
19
+
20
+ assert_not_equal key, @authentication.skey
21
+ end
22
+
23
+ should 'generate the correct skey with time offset' do
24
+ offset = 10
25
+ assert_equal correct_key(@authentication, @time + offset * 10), @authentication.skey(offset)
26
+ end
27
+
28
+ should 'generate the incorrect skey with wrong time offset' do
29
+ assert_not_equal correct_key(@authentication, @time + 1000), @authentication.skey(10)
30
+ end
31
+
32
+ should 'validate a correct key' do
33
+ assert @authentication.valid? correct_key(@authentication, @time)
34
+ end
35
+
36
+ should 'not validate an incorrect key' do
37
+ assert !(@authentication.valid? correct_key(@authentication, @time + 10))
38
+ end
39
+
40
+ should 'validate a correct key with tolerance' do
41
+ @authentication.tolerance = 5
42
+ assert @authentication.valid? correct_key(@authentication, @time + 50)
43
+ assert @authentication.valid? correct_key(@authentication, @time - 50)
44
+ end
45
+
46
+ should 'not validate a key out of tolerance' do
47
+ @authentication.tolerance = 5
48
+ assert !(@authentication.valid? correct_key(@authentication, @time + 100))
49
+ assert !(@authentication.valid? correct_key(@authentication, @time - 100))
50
+ end
51
+
52
+ context 'method' do
53
+ should 'raise an exception if there are not all required arguments' do
54
+ [:user_id, :host, :skey].each do |param|
55
+ hash = authentication_hash(@authentication)
56
+ hash.delete param
57
+ assert_raise(RuntimeError) { authenticated? hash }
58
+ end
59
+ end
60
+
61
+ should 'authenticate a valid user' do
62
+ assert authenticated? authentication_hash(@authentication)
63
+ end
64
+
65
+ should 'not authenticate an invalid user' do
66
+ hash = authentication_hash(@authentication)
67
+ hash[:user_id] = 2
68
+
69
+ assert !(authenticated? hash)
70
+ end
71
+
72
+ should 'authenticate a user with time offset' do
73
+ hash = authentication_hash(@authentication)
74
+ hash[:server_time_offset] = 1000
75
+ hash[:time] = Time.now - 1000
76
+
77
+ assert authenticated? hash
78
+ end
79
+
80
+ should 'not authenticate a user with wrong time offset' do
81
+ hash = authentication_hash(@authentication)
82
+ hash[:server_time_offset] = 1000
83
+
84
+ assert !(authenticated? hash)
85
+ end
86
+ end
87
+ end
88
+
89
+ def correct_key(authentication, time)
90
+ Digest::SHA1.hexdigest("#{authentication.user_id}#{time.to_i / 10}#{authentication.client_host_name}#{authentication.secret}")
91
+ end
92
+
93
+ def authentication_hash(authentication)
94
+ {
95
+ :user_id => @authentication.user_id,
96
+ :host => @authentication.client_host_name,
97
+ :skey => correct_key(@authentication, @time),
98
+ :secret => @authentication.secret
99
+ }
100
+ end
101
+ end
data/tuwien_logon.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tuwien_logon}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Clemens Helm"]
12
- s.date = %q{2010-04-15}
12
+ s.date = %q{2010-04-21}
13
13
  s.description = %q{Provides an authentication solution for ruby applications being used at the Vienna University of Technology}
14
14
  s.email = %q{clemens.helm@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -40,6 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.summary = %q{Ruby client for Vienna UT authentication service}
41
41
  s.test_files = [
42
42
  "test/helper.rb",
43
+ "test/test_authentication.rb",
43
44
  "test/test_tuwien_logon.rb",
44
45
  "test/test_user_info.rb",
45
46
  "test/test_user_info_request.rb"
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Clemens Helm
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-15 00:00:00 +02:00
17
+ date: 2010-04-21 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -86,6 +86,7 @@ specification_version: 3
86
86
  summary: Ruby client for Vienna UT authentication service
87
87
  test_files:
88
88
  - test/helper.rb
89
+ - test/test_authentication.rb
89
90
  - test/test_tuwien_logon.rb
90
91
  - test/test_user_info.rb
91
92
  - test/test_user_info_request.rb