tuwien_logon 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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Clemens Helm
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.rdoc ADDED
@@ -0,0 +1,46 @@
1
+ = tuwien_logon
2
+
3
+ This gem is an authentication solution for ruby applications being used at the Vienna University of Technology.
4
+
5
+ == Note
6
+
7
+ You will only be able to use this gem for authentication if you have already registered your application at the ZID. Find more information at http://www.zid.tuwien.ac.at/sts/dateninfrastruktur/authentifizierungsservice/.
8
+ Unfortunately this page is only provided in german though.
9
+
10
+ == Usage
11
+
12
+ For now only retrieving user information by their oid is implemented.
13
+
14
+ user = TuwienLogon::UserInfo.find_by_oid(1234567)
15
+
16
+ The following attributes can be accessed on success:
17
+
18
+ user.oid
19
+ user.firstname
20
+ user.lastname
21
+ user.title
22
+ user.matriculation_number
23
+ user.institute_symbol
24
+
25
+ You can change the name of these attributes in the configuration.
26
+
27
+ == Configuration
28
+
29
+ You can alter the following configuration options, here their default values are shown:
30
+
31
+ Tuwien.config.user_info_url = 'https://iu.zid.tuwien.ac.at/AuthServ.userInfo'
32
+ Tuwien.config.user_info_params = [:oid, :firstname, :lastname, :title, :matriculation_number, :institute_symbol]
33
+
34
+ == Note on Patches/Pull Requests
35
+
36
+ * Fork the project.
37
+ * Make your feature addition or bug fix.
38
+ * Add tests for it. This is important so I don't break it in a
39
+ future version unintentionally.
40
+ * Commit, do not mess with rakefile, version, or history.
41
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
42
+ * Send me a pull request. Bonus points for topic branches.
43
+
44
+ == Copyright
45
+
46
+ Copyright (c) 2010 Clemens Helm. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "tuwien_logon"
8
+ gem.summary = %Q{Ruby client for Vienna UT authentication service}
9
+ gem.description = %Q{Provides an authentication solution for ruby applications being used at the Vienna University of Technology}
10
+ gem.email = "clemens.helm@gmail.com"
11
+ gem.homepage = "http://github.com/dropswap/tuwien_logon"
12
+ gem.authors = ["Clemens Helm"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "tuwien_logon #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,16 @@
1
+ require 'singleton'
2
+
3
+ module TuwienLogon
4
+ class Configuration
5
+ include Singleton
6
+
7
+ attr_accessor :authentication_url, :user_info_url, :secret, :user_info_params
8
+
9
+ def initialize
10
+ @authentication_url = 'https://iu.zid.tuwien.ac.at/AuthServ.authenticate'
11
+ @user_info_url = 'https://iu.zid.tuwien.ac.at/AuthServ.userInfo'
12
+ @secret = '123456'
13
+ @user_info_params = [:oid, :firstname, :lastname, :title, :matriculation_number, :institute_symbol]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,31 @@
1
+ module TuwienLogon
2
+ class UserInfo
3
+ attr_accessor :params, :info
4
+
5
+ class << self
6
+ def find_by_oid(oid)
7
+ request = TuwienLogon::UserInfoRequest.new
8
+ request.get_user_info :oid => oid
9
+ end
10
+ end
11
+
12
+ def initialize(params = [])
13
+ @params = params
14
+ @info = {}
15
+ end
16
+
17
+ def method_missing(param, *args)
18
+ if param.to_s[-1] == '='
19
+ setter = true
20
+ param = param.to_s[0..-2].to_sym
21
+ end
22
+
23
+ if params.include? param
24
+ info[param] = args[0] if setter
25
+ info[param]
26
+ else
27
+ super(param, args);
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,40 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'tuwien_logon/user_info'
4
+
5
+ module TuwienLogon
6
+ class UserInfoRequest
7
+ attr_accessor :url
8
+
9
+ def initialize(url = TuwienLogon.config.user_info_url)
10
+ @url = URI.parse(url)
11
+ end
12
+
13
+ def split_response(response)
14
+ response.strip.split("\t")
15
+ end
16
+
17
+ def get_user_info(params = {})
18
+ create_user_info(get(params))
19
+ end
20
+
21
+ def create_user_info(infos = [], params = TuwienLogon.config.user_info_params)
22
+ infos = split_response(infos.to_s) unless infos.is_a? Array
23
+
24
+ userdata = TuwienLogon::UserInfo.new(params)
25
+ TuwienLogon.config.user_info_params.each_with_index do |param, index|
26
+ userdata.send("#{param}=".to_sym, infos[index]) unless infos[index].nil? || infos[index].empty?
27
+ end
28
+ userdata
29
+ end
30
+
31
+ def get(params = {})
32
+ url.query = query_string(params)
33
+ Net::HTTP.get_response(url).body
34
+ end
35
+
36
+ def query_string(params = {})
37
+ params.map { |key, value| "#{key}=#{value}" }.join('&')
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,10 @@
1
+ require 'tuwien_logon/configuration'
2
+ require 'tuwien_logon/user_info_request'
3
+
4
+ module TuwienLogon
5
+ class << self
6
+ def config
7
+ TuwienLogon::Configuration.instance
8
+ end
9
+ end
10
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'tuwien_logon'
8
+
9
+ class Test::Unit::TestCase
10
+ def setup
11
+ TuwienLogon.config.authentication_url = 'http://localhost:4567/AuthServ.authenticate'
12
+ TuwienLogon.config.user_info_url = 'http://localhost:4567/AuthServ.userInfo'
13
+ TuwienLogon.config.secret = '123456'
14
+ TuwienLogon.config.user_info_params = [:oid, :firstname, :lastname, :title, :matriculation_number, :institute_symbol]
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ require 'helper'
2
+
3
+ class TestTuwienLogon < Test::Unit::TestCase
4
+ should "set the authentication url correctly" do
5
+ url = 'abc'
6
+ TuwienLogon.config.authentication_url = url
7
+ assert_equal url, TuwienLogon.config.authentication_url
8
+ end
9
+
10
+ should "set the user info url correctly" do
11
+ url = 'abc'
12
+ TuwienLogon.config.user_info_url = url
13
+ assert_equal url, TuwienLogon.config.user_info_url
14
+ end
15
+
16
+ should "set the secret correctly" do
17
+ url = 'abc'
18
+ TuwienLogon.config.secret = url
19
+ assert_equal url, TuwienLogon.config.secret
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ require 'helper'
2
+ require 'tuwien_logon/user_info'
3
+
4
+ class TestUserInfo < Test::Unit::TestCase
5
+ context "A user info object" do
6
+ should "find correct user info" do
7
+ info = TuwienLogon::UserInfo.find_by_oid(1231132)
8
+ assert_equal '1231132', info.oid
9
+ assert_equal 'Ernst', info.firstname
10
+ assert_equal 'Orwell', info.lastname
11
+ assert_nil info.title
12
+ assert_equal '0812345', info.matriculation_number
13
+ assert_nil info.institute_symbol
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,52 @@
1
+ require 'helper'
2
+ require 'tuwien_logon/user_info_request'
3
+
4
+ class TestUserInfoRequest < Test::Unit::TestCase
5
+ context "A user info request" do
6
+ setup do
7
+ @request = TuwienLogon::UserInfoRequest.new
8
+ @request.url.query = 'oid=8761231'
9
+ end
10
+
11
+ should "parse a url correctly" do
12
+ assert_equal 'localhost', @request.url.host
13
+ assert_equal '/AuthServ.userInfo', @request.url.path
14
+ assert_equal 4567, @request.url.port
15
+ assert_equal 'http', @request.url.scheme
16
+ assert_equal 'oid=8761231', @request.url.query
17
+ end
18
+
19
+ should "map params correctly" do
20
+ query = @request.query_string(:a => 'b', :c => 'd')
21
+ assert_equal 'a=b&c=d', query
22
+ end
23
+
24
+ should "parse user info correctly" do
25
+ data = "124\tAlbert\tEinstein\tDr.\t0123456\tabc\n"
26
+ info = @request.create_user_info data, [:oid, :firstname, :lastname, :title, :matriculation_number, :institute_symbol]
27
+ assert_equal '124', info.oid
28
+ assert_equal 'Albert', info.firstname
29
+ assert_equal 'Einstein', info.lastname
30
+ assert_equal 'Dr.', info.title
31
+ assert_equal '0123456', info.matriculation_number
32
+ assert_equal 'abc', info.institute_symbol
33
+ end
34
+
35
+ # for the following tests mockzid must be running at localhost:4567
36
+
37
+ should "retrieve correct reply" do
38
+ reply = @request.get :oid => 8761231
39
+ assert_equal "8761231\tKarl\tPopper\tProf.\t\tE123\n", reply
40
+ end
41
+
42
+ should "get the correct user info" do
43
+ info = @request.get_user_info(:oid => 1231132)
44
+ assert_equal '1231132', info.oid
45
+ assert_equal 'Ernst', info.firstname
46
+ assert_equal 'Orwell', info.lastname
47
+ assert_nil info.title
48
+ assert_equal '0812345', info.matriculation_number
49
+ assert_nil info.institute_symbol
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{tuwien_logon}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Clemens Helm"]
12
+ s.date = %q{2010-04-15}
13
+ s.description = %q{Provides an authentication solution for ruby applications being used at the Vienna University of Technology}
14
+ s.email = %q{clemens.helm@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/tuwien_logon.rb",
27
+ "lib/tuwien_logon/configuration.rb",
28
+ "lib/tuwien_logon/user_info.rb",
29
+ "lib/tuwien_logon/user_info_request.rb",
30
+ "test/helper.rb",
31
+ "test/test_tuwien_logon.rb",
32
+ "test/test_user_info.rb",
33
+ "test/test_user_info_request.rb",
34
+ "tuwien_logon.gemspec"
35
+ ]
36
+ s.homepage = %q{http://github.com/dropswap/tuwien_logon}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.6}
40
+ s.summary = %q{Ruby client for Vienna UT authentication service}
41
+ s.test_files = [
42
+ "test/helper.rb",
43
+ "test/test_tuwien_logon.rb",
44
+ "test/test_user_info.rb",
45
+ "test/test_user_info_request.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
59
+ end
60
+ end
61
+
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tuwien_logon
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Clemens Helm
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-15 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ description: Provides an authentication solution for ruby applications being used at the Vienna University of Technology
33
+ email: clemens.helm@gmail.com
34
+ executables: []
35
+
36
+ extensions: []
37
+
38
+ extra_rdoc_files:
39
+ - LICENSE
40
+ - README.rdoc
41
+ files:
42
+ - .document
43
+ - .gitignore
44
+ - LICENSE
45
+ - README.rdoc
46
+ - Rakefile
47
+ - VERSION
48
+ - lib/tuwien_logon.rb
49
+ - lib/tuwien_logon/configuration.rb
50
+ - lib/tuwien_logon/user_info.rb
51
+ - lib/tuwien_logon/user_info_request.rb
52
+ - test/helper.rb
53
+ - test/test_tuwien_logon.rb
54
+ - test/test_user_info.rb
55
+ - test/test_user_info_request.rb
56
+ - tuwien_logon.gemspec
57
+ has_rdoc: true
58
+ homepage: http://github.com/dropswap/tuwien_logon
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.6
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Ruby client for Vienna UT authentication service
87
+ test_files:
88
+ - test/helper.rb
89
+ - test/test_tuwien_logon.rb
90
+ - test/test_user_info.rb
91
+ - test/test_user_info_request.rb