sessionvoc-open 1.7.3

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.
@@ -0,0 +1,59 @@
1
+ # Copyright:: 2011 triAGENS GmbH
2
+ # Author:: Oliver Kiessler (mailto:kiessler@inceedo.com)
3
+ module Sessionvoc
4
+ module Open
5
+ # Raised when no SessionVOC client could be created due to a missing configuration.
6
+ class ConfigurationMissingException < Exception; end
7
+
8
+ # The SessionVOC server is not accessible with this configuration.
9
+ class ConnectionRefusedException < Exception; end
10
+
11
+ # Raised when the SessionVOC server could not create a new session.
12
+ class SessionCreationFailureException < Exception; end
13
+
14
+ # Raised when no or an invalid session id is used and it is unknown to SessionVOC.
15
+ class InvalidSidException < Exception; end
16
+
17
+ # Raised when the session identified by a sid could not be deleted.
18
+ class SessionDeletionFailure < Exception; end
19
+
20
+ # Raised when invalid JSON is passed to SessionVOC.
21
+ class InvalidJSONException < Exception; end
22
+
23
+ # Raised when an unidentified problem occured.
24
+ class UnknownException < Exception; end
25
+
26
+ # Raised when the given credentials are unknown to SessionVOC.
27
+ class AuthentificationFailedException < Exception; end
28
+
29
+ # Raised when an illegal user identifier is passed to SessionVOC.
30
+ class IllegalUserIdentifierException < Exception; end
31
+
32
+ # Raised when an illegal authentification request is passed to SessionVOC.
33
+ class IllegalAuthentificationRequestException < Exception; end
34
+
35
+ # Raised when an illegal request is passed to SessionVOC.
36
+ class IllegalRequestException < Exception; end
37
+
38
+ # Raised when an internal server error occurs in SessionVOC.
39
+ class InternalServerErrorException < Exception; end
40
+
41
+ # Raised when an unknown or invalid form id is passed to SessionVOC.
42
+ class InvalidFidException < Exception; end
43
+
44
+ # Raised when a form data problem occurred in SessionVOC.
45
+ class FormDataCantBeDestroyedException < Exception; end
46
+
47
+ # Raised when a form data problem occurred in SessionVOC.
48
+ class FormDataCantBeModifiedException < Exception; end
49
+
50
+ # Raised when an unsupported functionality in this ruby library was used.
51
+ class NotSupportedException < Exception; end
52
+
53
+ # Raised when the given data could not be converted to the data types expected by SessionVOC.
54
+ class DataConversionException < Exception; end
55
+
56
+ # Raised when an unknown, temporary error in SessionVOC occurs.
57
+ class TemporaryErrorException < Exception; end
58
+ end
59
+ end
@@ -0,0 +1,64 @@
1
+ # Copyright:: 2011 triAGENS GmbH
2
+ # Author:: Oliver Kiessler (mailto:kiessler@inceedo.com)
3
+ module Sessionvoc
4
+ module Open
5
+ # The methods in this module handle all form data relevant actions.
6
+ module FormData
7
+ # Creates a new form context within a given session and returns a fid which identifies the form context.
8
+ # === Parameters
9
+ # * sid = Session Id
10
+ # * options
11
+ def create_form_data(sid, options = {})
12
+ response = get_response(:post, "/formdata/#{sid}")
13
+ if response_ok?(response)
14
+ response.parsed_response["fid"]
15
+ else
16
+ handle_exception(response.parsed_response["errorCode"], response.parsed_response["message"])
17
+ end
18
+ end
19
+
20
+ # Deletes a form context within a session.
21
+ # === Parameters
22
+ # * sid = Session Id
23
+ # * fid = Form Id
24
+ # * options
25
+ def delete_form_data(sid, fid, options = {})
26
+ response = get_response(:delete, "/formdata/#{sid}/#{fid}")
27
+ if response_ok?(response)
28
+ response.parsed_response["deleted"]
29
+ else
30
+ handle_exception(response.parsed_response["errorCode"], response.parsed_response["message"])
31
+ end
32
+ end
33
+
34
+ # Returns the contents of a form context within a session.
35
+ # === Parameters
36
+ # * sid = Session Id
37
+ # * fid = Form Id
38
+ # * options
39
+ def get_form_data(sid, fid, options = {})
40
+ response = get_response(:get, "/formdata/#{sid}/#{fid}")
41
+ if response and response.response.is_a?(Net::HTTPOK)
42
+ response.parsed_response
43
+ else
44
+ handle_exception(response.parsed_response["errorCode"], response.parsed_response["message"])
45
+ end
46
+ end
47
+
48
+ # Updates/replaces the form data in SessionVOC with the form_data passed to this method.
49
+ # === Parameters
50
+ # * sid = Session Id
51
+ # * fid = Form Id
52
+ # * form_data = Form data hash
53
+ # * options
54
+ def update_form_data(sid, fid, form_data, options = {})
55
+ response = get_response(:put, "/formdata/#{sid}/#{fid}", {:body => form_data.to_json})
56
+ if response_ok?(response)
57
+ (response.parsed_response['sid'] and response.parsed_response['fid'])
58
+ else
59
+ handle_exception(response.parsed_response["errorCode"], response.parsed_response["message"])
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,18 @@
1
+ # Copyright:: 2011 triAGENS GmbH
2
+ # Author:: Oliver Kiessler (mailto:kiessler@inceedo.com)
3
+ module Sessionvoc
4
+ module Open
5
+ # The methods in this module handle all meta data related actions.
6
+ module MetaData
7
+ # Returns meta data info from the SessionVOC server. Includes types and access permissions.
8
+ def datainfo
9
+ response = get_response(:get, "/datainfo")
10
+ if response_ok?(response)
11
+ return response.parsed_response
12
+ else
13
+ raise Sessionvoc::Open::UnknownException
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,63 @@
1
+ # Copyright:: 2011 triAGENS GmbH
2
+ # Author:: Oliver Kiessler (mailto:kiessler@inceedo.com)
3
+ module Sessionvoc
4
+ module Open
5
+ # The methods in this module handle all session related actions.
6
+ module Session
7
+ # Creates a new session in the SessionVOC server and returns a sid.
8
+ def new_session
9
+ response = get_response(:post, "/session")
10
+ if response_ok?(response)
11
+ return response.parsed_response["sid"]
12
+ else
13
+ raise Sessionvoc::Open::SessionCreationFailureException
14
+ end
15
+ end
16
+
17
+ # Deletes an existing session in the SessionVOC server.
18
+ # === Parameters
19
+ # * sid = Session Id
20
+ def delete_session(sid)
21
+ response = get_response(:delete, "/session/#{sid}")
22
+ if response_ok?(response) and response.parsed_response["deleted"]
23
+ return true
24
+ else
25
+ handle_exception(response.parsed_response["errorCode"], response.parsed_response["message"])
26
+ end
27
+ end
28
+
29
+ # Updates the contents of the session in the SessionVOC server. Pass in a session_data hash containing the "transData" und "userData"
30
+ # sections.
31
+ # === Parameters
32
+ # * sid = Session Id
33
+ # * session_data = Session data hash
34
+ # * options
35
+ def update(sid, session_data, options = {})
36
+ logger.debug("Session Data for sid #{sid}: #{session_data.inspect}")
37
+ body = {}
38
+ body['transData'] = session_data['transData'] if session_data['transData'] and not session_data['transData'].empty?
39
+ body['userData'] = session_data['userData'] if session_data['userData'] and not session_data['userData'].empty?
40
+ logger.debug("Body JSON: #{body.to_json}")
41
+ response = get_response(:put, "/session/#{sid}", {:body => body.to_json})
42
+ response_ok?(response) ? response.parsed_response : handle_exception(response.parsed_response["errorCode"], response.parsed_response["message"])
43
+ end
44
+
45
+ # Alias for get_session.
46
+ # === Parameters
47
+ # * sid
48
+ def output(sid); get_session(sid); end
49
+
50
+ # Retuns the contents of a session from the SessionVOC server as a hash.
51
+ # === Parameters
52
+ # * sid = Session Id
53
+ def get_session(sid)
54
+ response = get_response(:get, "/session/#{sid}")
55
+ if response_ok?(response)
56
+ return response.parsed_response
57
+ else
58
+ raise Sessionvoc::Open::InvalidSidException
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,103 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sessionvoc-open}
8
+ s.version = "1.7.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["triAGENS GmbH", "Oliver Kiessler"]
12
+ s.date = %q{2011-04-14}
13
+ s.description = %q{Rails 3 Plugin to integrate with SessionVOC. In order to manage user sessions efficiently the SessionVOC provides the functions login, logout, read and write of a session. Furthermore it has the ability to synchronize with one or more persistent relational databases.}
14
+ s.email = %q{kiessler@inceedo.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "config.yml.sample",
28
+ "examples/example.sql",
29
+ "examples/example.xml",
30
+ "init.rb",
31
+ "install.rb",
32
+ "lib/sessionvoc-open.rb",
33
+ "lib/sessionvoc-store/open/controller_methods.rb",
34
+ "lib/sessionvoc-store/open/railtie.rb",
35
+ "lib/sessionvoc-store/open/sessionvoc_store.rb",
36
+ "lib/sessionvoc/open/authentification.rb",
37
+ "lib/sessionvoc/open/base.rb",
38
+ "lib/sessionvoc/open/client.rb",
39
+ "lib/sessionvoc/open/configuration.rb",
40
+ "lib/sessionvoc/open/data_conversion.rb",
41
+ "lib/sessionvoc/open/exceptions.rb",
42
+ "lib/sessionvoc/open/form_data.rb",
43
+ "lib/sessionvoc/open/meta_data.rb",
44
+ "lib/sessionvoc/open/session.rb",
45
+ "test/config.yml",
46
+ "test/helper.rb",
47
+ "test/test_sessionvoc_authentification.rb",
48
+ "test/test_sessionvoc_base.rb",
49
+ "test/test_sessionvoc_data_conversion.rb",
50
+ "test/test_sessionvoc_form_data.rb",
51
+ "test/test_sessionvoc_meta_data.rb",
52
+ "test/test_sessionvoc_session.rb",
53
+ "uninstall.rb"
54
+ ]
55
+ s.homepage = %q{http://www.worldofvoc.com/products/sessionvoc/summary/}
56
+ s.licenses = ["Apache License Version 2.0, January 2004"]
57
+ s.require_paths = ["lib"]
58
+ s.rubygems_version = %q{1.5.2}
59
+ s.summary = %q{The SessionVOC is a noSQL database optimized for the management of user sessions.}
60
+ s.test_files = [
61
+ "test/helper.rb",
62
+ "test/test_sessionvoc_authentification.rb",
63
+ "test/test_sessionvoc_base.rb",
64
+ "test/test_sessionvoc_data_conversion.rb",
65
+ "test/test_sessionvoc_form_data.rb",
66
+ "test/test_sessionvoc_meta_data.rb",
67
+ "test/test_sessionvoc_session.rb"
68
+ ]
69
+
70
+ if s.respond_to? :specification_version then
71
+ s.specification_version = 3
72
+
73
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
74
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
75
+ s.add_runtime_dependency(%q<json>, [">= 0"])
76
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
77
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
78
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
79
+ s.add_development_dependency(%q<rcov>, [">= 0"])
80
+ s.add_runtime_dependency(%q<httparty>, [">= 0.7.4"])
81
+ s.add_runtime_dependency(%q<json>, [">= 1.4.6"])
82
+ else
83
+ s.add_dependency(%q<httparty>, [">= 0"])
84
+ s.add_dependency(%q<json>, [">= 0"])
85
+ s.add_dependency(%q<shoulda>, [">= 0"])
86
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
87
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
88
+ s.add_dependency(%q<rcov>, [">= 0"])
89
+ s.add_dependency(%q<httparty>, [">= 0.7.4"])
90
+ s.add_dependency(%q<json>, [">= 1.4.6"])
91
+ end
92
+ else
93
+ s.add_dependency(%q<httparty>, [">= 0"])
94
+ s.add_dependency(%q<json>, [">= 0"])
95
+ s.add_dependency(%q<shoulda>, [">= 0"])
96
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
97
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
98
+ s.add_dependency(%q<rcov>, [">= 0"])
99
+ s.add_dependency(%q<httparty>, [">= 0.7.4"])
100
+ s.add_dependency(%q<json>, [">= 1.4.6"])
101
+ end
102
+ end
103
+
data/test/config.yml ADDED
@@ -0,0 +1,5 @@
1
+ protocol: http
2
+ host: localhost
3
+ port: 8208
4
+ strict_mode: true
5
+ auth: simple
data/test/helper.rb ADDED
@@ -0,0 +1,38 @@
1
+ # Copyright:: 2011 triAGENS GmbH
2
+ # Author:: Oliver Kiessler (mailto:kiessler@inceedo.com)
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'test/unit'
13
+ require 'shoulda'
14
+ require 'digest'
15
+
16
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
17
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
18
+ require 'sessionvoc-open'
19
+
20
+ class Test::Unit::TestCase
21
+ def non_sid
22
+ "473878374888888888888zfgiusdhfkhsdfz843z987843975893745897389#{rand(10)}#{Time.now.to_i}"
23
+ end
24
+
25
+ def non_fid
26
+ "3748748#{rand(10)}#{Time.now.to_i}"
27
+ end
28
+
29
+ def client
30
+ port = ENV['SESSIONVOC_PORT']
31
+ host = ENV['SESSIONVOC_HOST']
32
+ if host and port
33
+ @client ||= Sessionvoc::Open::Client.new('host' => host, 'port' => port, 'log_level' => Logger::DEBUG)
34
+ else
35
+ @client ||= Sessionvoc::Open::Client.new('log_level' => Logger::DEBUG)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,62 @@
1
+ # Copyright:: 2011 triAGENS GmbH
2
+ # Author:: Oliver Kiessler (mailto:kiessler@inceedo.com)
3
+ require 'helper'
4
+
5
+ class TestSessionvocAuthentification < Test::Unit::TestCase
6
+ should "perform a simple authentification" do
7
+ sid = client.new_session
8
+ assert client.simple(sid, 'testuser', 'tester')
9
+ end
10
+
11
+ should "fail to perform a simple authentification due to a non-existing sid" do
12
+ sid = client.new_session
13
+ assert non_sid != sid
14
+ assert_raise Sessionvoc::Open::InvalidSidException do
15
+ client.simple(non_sid, 'testuser', 'tester')
16
+ end
17
+ end
18
+
19
+ should "perform a logout" do
20
+ sid = client.new_session
21
+ assert client.simple(sid, 'testuser', 'tester')
22
+ assert client.logout(sid)
23
+ end
24
+
25
+ should "perform the correct encryption and hashing" do
26
+ assert_equal client.send(:encrypt_password, 'tester', 'abcdef', Sessionvoc::Open::Base::HASH_TYPES[:HASH_NONE]), 'tester'
27
+ assert_equal client.send(:encrypt_password, 'tester', 'abcdef', Sessionvoc::Open::Base::HASH_TYPES[:HASH_SHA1]), 'db1e80e88bdeb3182c368f2b9d798431'
28
+ assert_equal client.send(:encrypt_password, 'tester', 'abcdef', Sessionvoc::Open::Base::HASH_TYPES[:HASH_MD5]), '8310a7f94396ec64c9221227ba5c667e'
29
+
30
+ assert_raise Sessionvoc::Open::NotSupportedException do
31
+ client.send(:encrypt_password, 'tester', 'abcdef', Sessionvoc::Open::Base::HASH_TYPES[:HASH_SHA224])
32
+ end
33
+
34
+ assert_raise Sessionvoc::Open::NotSupportedException do
35
+ client.send(:encrypt_password, 'tester', 'abcdef', Sessionvoc::Open::Base::HASH_TYPES[:HASH_SHA256])
36
+ end
37
+ end
38
+
39
+ should "create a nonce" do
40
+ nonce = client.create_nonce
41
+ assert_not_nil nonce
42
+ assert_equal nonce.length, 17
43
+ timestamp = Time.now.to_i
44
+ random_number = client.gen_64bit_id
45
+ local_nonce = Base64.encode64("#{timestamp.to_s[0..3]}#{random_number[4..11]}")
46
+ nonce = client.create_nonce(timestamp, random_number)
47
+ assert_not_nil nonce
48
+ assert_equal nonce.length, 17
49
+ assert_equal nonce, local_nonce
50
+
51
+ nonce = client.create_nonce(timestamp, random_number, {:no_encode => true})
52
+ assert_equal nonce, "#{timestamp.to_s[0..3]}#{random_number[4..11]}"
53
+ end
54
+
55
+ should "check the status of a nonce" do
56
+ 10.times do
57
+ nonce = client.create_nonce
58
+ assert client.get_nonce(nonce)
59
+ assert !client.get_nonce(nonce)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,62 @@
1
+ # Copyright:: 2011 triAGENS GmbH
2
+ # Author:: Oliver Kiessler (mailto:kiessler@inceedo.com)
3
+ require 'helper'
4
+ require "ftools"
5
+
6
+ class TestSessionvocBase < Test::Unit::TestCase
7
+ should "initialize configuration" do
8
+ client = Sessionvoc::Open::Client.new('protocol' => 'http', 'host' => 'localhost', 'port' => '12345',
9
+ 'log_level' => Logger::DEBUG, 'strict_mode' => true)
10
+ assert_not_nil client
11
+ assert_not_nil client.configuration
12
+ assert_not_nil client.configuration.options
13
+ assert_not_nil client.logger
14
+
15
+ assert_equal client.configuration.options['protocol'], 'http'
16
+ assert_equal client.configuration.options['host'], 'localhost'
17
+ assert_equal client.configuration.options['port'], '12345'
18
+ assert_equal client.configuration.options['log_level'], Logger::DEBUG
19
+ assert client.configuration.options['strict_mode']
20
+ end
21
+
22
+ should "return error codes" do
23
+ client = Sessionvoc::Open::Client.new('host' => 'localhost', 'port' => '12345', 'strict_mode' => true)
24
+ assert_not_nil client.send(:codes)
25
+ end
26
+
27
+ should "return correct server base url based on configuration" do
28
+ client = Sessionvoc::Open::Client.new('host' => 'localhost', 'port' => '12345')
29
+ assert_equal client.send(:base_url), 'http://localhost:12345'
30
+
31
+ client2 = Sessionvoc::Open::Client.new('protocol' => 'https', 'host' => 'localhost', 'port' => '8080')
32
+ assert_equal client2.send(:base_url), 'https://localhost:8080'
33
+ end
34
+
35
+ should 'initialize configuration from yml file from current directory' do
36
+ client = Sessionvoc::Open::Client.new
37
+ assert_equal client.configuration.options['protocol'], 'http'
38
+ assert_equal client.configuration.options['host'], 'localhost'
39
+ assert_equal client.configuration.options['port'], '8208'
40
+ assert client.configuration.options['strict_mode']
41
+ assert_equal client.configuration.options['auth'], 'none'
42
+ end
43
+
44
+ should "read configuration" do
45
+ assert_not_nil (client = Sessionvoc::Open::Client.new)
46
+ File.copy('test/config.yml', './config.yml')
47
+ client.send(:read_configuration)
48
+ assert_not_nil client.configuration
49
+ File.delete('./config.yml')
50
+ end
51
+
52
+ should "set the strict mode" do
53
+ client = Sessionvoc::Open::Client.new('host' => 'localhost', 'port' => '12345', 'strict_mode' => true)
54
+ assert client.send(:use_strict_mode?)
55
+ client = Sessionvoc::Open::Client.new('host' => 'localhost', 'port' => '12345', 'strict_mode' => false)
56
+ assert !client.send(:use_strict_mode?)
57
+ end
58
+
59
+ should 'return client version' do
60
+ assert_equal Sessionvoc::Open::Client::VERSION, '1.7.3'
61
+ end
62
+ end