cul-handles 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,6 @@
1
+ *.sw?
2
+ private
3
+ .DS_Store
4
+ coverage
5
+ rdoc
6
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 James Stuart
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,18 @@
1
+ = cul-handles
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 James Stuart. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "cul-handles"
8
+ gem.summary = %Q{CUL Handle Client}
9
+ gem.description = %Q{Columbia client to deal with handle server}
10
+ gem.email = "tastyhat@jamesstuart.org"
11
+ gem.homepage = "http://github.com/tastyhat/cul-handles"
12
+ gem.authors = ["James Stuart"]
13
+ gem.add_development_dependency "thoughtbot-shoulda"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION')
47
+ version = File.read('VERSION')
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "cul-handles #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,16 @@
1
+ require 'socket'
2
+ require 'digest/sha1'
3
+
4
+ require 'cul/handles/hdl'
5
+
6
+ require "cul/handles/client"
7
+ require "cul/handles/base_message"
8
+ require 'cul/handles/base_response'
9
+ require "cul/handles/base_request"
10
+ require "cul/handles/session_request"
11
+ require 'cul/handles/resolution_request'
12
+ require 'cul/handles/resolution_response'
13
+ require 'cul/handles/handle_value_request'
14
+ require 'cul/handles/challenge_response'
15
+ require 'cul/handles/challenge_answer_request'
16
+ require 'cul/handles/delete_handle_request'
@@ -0,0 +1,105 @@
1
+ require "test_helper"
2
+
3
+ module Cul
4
+ module Handles
5
+ class AuthnTest < Test::Unit::TestCase
6
+ include Hdl
7
+ DEFAULT_ADMIN = "10022/ADMIN"
8
+ def testAdminHandleValueEncoding
9
+ permissions = PERM_ALL
10
+ adminHandle = DEFAULT_ADMIN
11
+ index = 300
12
+ expected = {'permissions' => permissions, 'handle' => adminHandle, 'index' => index}
13
+
14
+ vbytes = encodeAdminData(adminHandle, permissions, index)
15
+ actual = decodeAdminData(vbytes)
16
+ assert_equal actual.keys, expected.keys
17
+ actual.each_key {|key|
18
+ assert_equal actual[key], expected[key]
19
+ }
20
+ end
21
+ def setup()
22
+
23
+ @handle_config = YAML::load_file("private/config.yml")
24
+
25
+ @client = Client.new(@handle_config["host"],@handle_config["port"])
26
+ # from dspace config:
27
+ # handle.auth.handle = 10022/ADMIN
28
+ # handle.auth.index = 300
29
+ # handle.auth.passphrase = #######
30
+ @secret = @handle_config["secret"]
31
+ @handle = "10022/TESTDELETE"
32
+ @admin = "10022/ADMIN"
33
+ end
34
+ def testSessionSetup
35
+ @handle_config = YAML::load_file("private/config.yml")
36
+
37
+ if 1
38
+ return
39
+ end
40
+ server = @handle_config["host"]
41
+ port = @handle_config["port"]
42
+ sreq = SessionSetupRequest.new(@admin,INDEX_AUTH)
43
+ sreq.requestId=(0)
44
+ sreq.certify=(true)
45
+ cres = ChallengeResponse.new()
46
+ #res = SessionSetupResponse.new()
47
+ sock = TCPSocket.new(server,port)
48
+ cres.send(sreq, sock)
49
+ puts cres
50
+ creq = ChallengeAnswerRequest.new(cres.nonce,@admin,INDEX_AUTH)
51
+ creq.sessionId = cres.sessionId
52
+ creq.requestId = cres.requestId
53
+ sres = SessionSetupResponse.new()
54
+ sres.send(creq,sock)
55
+ sharedSecret = sreq.dh.secret(sres.serverKey)
56
+
57
+ puts(sres)
58
+ sock.close()
59
+ assert(sres.sessionId != 0, "returned sessionId was zero (0)")
60
+ end
61
+ def test001CreateHandle()
62
+ expectedValue = "http://www.columbia.edu/testCreateHandle/"
63
+ res = @client.createHandle(@secret, @handle, expectedValue)
64
+ if not res.responseCode.eql?1
65
+ puts "unexpected response code: " + res.responseCode.to_s
66
+ puts res
67
+ end
68
+ assert(res.responseCode.eql?(1),"unexpected response code: " + res.responseCode.to_s)
69
+ actualValue = @client.resolve(@handle).handleValue()
70
+ assert_equal(expectedValue, actualValue)
71
+ end
72
+ def test002DeleteValue()
73
+ res = @client.deleteHandleValue(@secret, @handle, "http://www.columbia.edu/testCreateHandle/")
74
+ if not res.responseCode.eql?1
75
+ puts "unexpected response code: " + res.responseCode.to_s
76
+ puts res
77
+ end
78
+ assert(res.responseCode.eql?(1),"unexpected response code: " + res.responseCode.to_s)
79
+ actualValue = @client.resolve(@handle).handleValue()
80
+ assert_nil(actualValue)
81
+ end
82
+ def test003AddValue()
83
+ expectedValue = "http://www.columbia.edu/addValue/"
84
+ res = @client.addHandleValue(@secret, @handle, expectedValue)
85
+ if not res.responseCode.eql?1
86
+ puts "unexpected response code: " + res.responseCode.to_s
87
+ puts res
88
+ end
89
+ assert(res.responseCode.eql?(1),"unexpected response code: " + res.responseCode.to_s)
90
+ actualValue = @client.resolve(@handle).handleValue()
91
+ assert_equal(expectedValue, actualValue)
92
+ end
93
+ def test004DeleteHandle()
94
+ res = @client.deleteHandle(@secret, @handle)
95
+ if not res.responseCode.eql?1
96
+ puts "unexpected response code: " + res.responseCode.to_s
97
+ puts res
98
+ end
99
+ assert(res.responseCode.eql?(1),"unexpected response code: " + res.responseCode.to_s)
100
+ actualResponse = @client.resolve(@handle)
101
+ assert_equal(Hdl::RC_HANDLE_NOT_FOUND,actualResponse.responseCode)
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class CulHandlesTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ # flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
data/test/dh_test.rb ADDED
@@ -0,0 +1,17 @@
1
+ module Cul
2
+ module Handles
3
+ class DHTest < Test::Unit::TestCase
4
+ def testDHKeys()
5
+ maxrand = (2**513) - 1
6
+ alice = DH.new(53, 5,maxrand)
7
+ bob = DH.new(53, 5, maxrand)
8
+ alice.generate
9
+ assert(alice.valid?)
10
+ bob.generate
11
+ assert(bob.valid?)
12
+ assert(alice.publickey != bob.publickey)
13
+ assert(alice.secret(bob.publickey) == bob.secret(alice.publickey))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+ module Cul
3
+ module Handles
4
+ class ResolutionTest < Test::Unit::TestCase
5
+ def testRequestPacketFormat
6
+ # expected value taken from output of Java client
7
+ # expiration time is fixed in expected value
8
+ # @expirationTime = [74,88,80,227] # for testing purposes!!!
9
+ # expected = "02010000000000000607010a00000000000000060000000100000000090000000f0f00000a01090f0000000a0000000e01000002020f01030a040a080602000000000000000000000000"
10
+ expected = ["0201000000000000000000000000000000000036000000010000000018000000ffff00004a6189cf0000001a0000000e31303032322f41433a543a383632000000000000000000000000"]
11
+ test = ResolutionRequest.new("10022/AC:T:862")
12
+ test.requestId = 0
13
+
14
+ test.siteInfoSerial = -1
15
+ test.sessionId = 0
16
+ test.expirationTime= 1247906255
17
+ actual = test.packet.pack('C*').unpack('H*')
18
+ assert_equal actual, expected
19
+ end
20
+ def testResolutionPacket()
21
+ expected = "10022/ba2213"
22
+ @handle_config = YAML::load_file("private/config.yml")
23
+
24
+ response = Cul::Handles::Client.new(@handle_config["host"],@handle_config["port"]).resolve(expected)
25
+ assert_equal response.responseCode, 1
26
+
27
+ actual = response.handle
28
+ assert_equal actual, expected
29
+
30
+ ctr = 0
31
+ expected = "http://www.columbia.edu/~ba2213/changes.txt"
32
+ actual = response.handleValue('URL')
33
+ assert_equal actual, expected
34
+ # response.packet.each { | byteVal|
35
+ # actual.concat("%02x" % byteVal)
36
+ # ctr = ctr + 1
37
+ # if ctr % 4 == 0
38
+ # actual.concat(" ")
39
+ # end
40
+ # }
41
+ # puts(actual)
42
+ # puts(response)
43
+ # rcode = response.responseCode
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'yaml'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+
9
+ require 'cul-handles'
10
+
11
+ class Test::Unit::TestCase
12
+
13
+ end
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+ module Cul
3
+ module Handles
4
+ class UnsignedIntegerTest < Test::Unit::TestCase
5
+ include Hdl
6
+ ASCII_ENCODED = [0,0,0,6,0x66,0x6f,0x6f,0x62,0x61,0x72]
7
+ ASCII_DECODED = "foobar"
8
+ ZERO_ENCODED = [0,0,0,0]
9
+ ZERO_DECODED = ""
10
+ UNICODE_ENCODED = [0,0,0,7,0x66,0x6f,0x6f,0x62,0xc4,0x81,0x72]
11
+ UNICODE_DECODED = "foobār"
12
+ def testUnsignedIntSerialization
13
+ # [ 16777216 , 65536, 256, 1]
14
+ input = [0x60,0xd4,0xee,0x52]
15
+ expected = 1624567378 # 1624567378
16
+ actual = fromBytes(input)
17
+ assert_equal actual, expected
18
+ end
19
+ def testUnsignedIntDeserialization
20
+ # [ 16777216 , 65536, 256, 1]
21
+ expected = [0x60,0xd4,0xee,0x52]
22
+ input = 1624567378 # 1624567378
23
+ actual = asBytes(input)
24
+ assert_equal actual, expected
25
+ end
26
+ def testProtocolStringEncode()
27
+ expected = ASCII_ENCODED
28
+ actual = toProtocolString(ASCII_DECODED)
29
+ assert_equal actual, expected
30
+
31
+ expected = ZERO_ENCODED
32
+ actual = toProtocolString(ZERO_DECODED)
33
+ assert_equal actual, expected
34
+
35
+ expected = UNICODE_ENCODED
36
+ actual = toProtocolString(UNICODE_DECODED)
37
+ assert_equal actual, expected
38
+ end
39
+
40
+ def testProtocolStringDecode()
41
+ expected = ASCII_DECODED
42
+ actual = readProtocolString(ASCII_ENCODED)[1]
43
+ assert_equal actual, expected
44
+
45
+ expected = ZERO_DECODED
46
+ actual = readProtocolString(ZERO_ENCODED)[1]
47
+ assert_equal actual, expected
48
+
49
+ expected = UNICODE_DECODED
50
+ actual = readProtocolString(UNICODE_ENCODED)[1]
51
+ assert_equal actual, expected
52
+ end
53
+
54
+ def stringAsHex(input)
55
+ input = input.unpack("U*")
56
+ bytesAsHex(input)
57
+ end
58
+ def bytesAsHex(input)
59
+ result = ''
60
+ ctr = 0
61
+ input.each { |byteVal|
62
+ result.concat("%02x" % byteVal)
63
+ ctr = ctr + 1
64
+ if ctr % 2 == 0
65
+ result.concat(" ")
66
+ end
67
+
68
+ }
69
+ result
70
+ end
71
+ end
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cul-handles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Stuart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-10 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Columbia client to deal with handle server
26
+ email: tastyhat@jamesstuart.org
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/cul-handles.rb
42
+ - test/cul-handles_test.rb
43
+ - test/test_helper.rb
44
+ has_rdoc: true
45
+ homepage: http://github.com/tastyhat/cul-handles
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: CUL Handle Client
72
+ test_files:
73
+ - test/authn_test.rb
74
+ - test/cul-handles_test.rb
75
+ - test/dh_test.rb
76
+ - test/resolution_test.rb
77
+ - test/test_helper.rb
78
+ - test/unsigned_integer_test.rb