coap 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +19 -0
- data/LICENSE +21 -0
- data/README.md +64 -0
- data/Rakefile +9 -0
- data/bin/client +42 -0
- data/coap.gemspec +25 -0
- data/lib/coap.rb +34 -0
- data/lib/coap/block.rb +45 -0
- data/lib/coap/client.rb +364 -0
- data/lib/coap/coap.rb +273 -0
- data/lib/coap/message.rb +187 -0
- data/lib/coap/mysocket.rb +81 -0
- data/lib/coap/observer.rb +41 -0
- data/lib/coap/version.rb +3 -0
- data/lib/misc/hexdump.rb +17 -0
- data/test/coap_test_helper.rb +2 -0
- data/test/disabled_econotag_blck.rb +33 -0
- data/test/test_client.rb +311 -0
- data/test/test_message.rb +127 -0
- metadata +113 -0
@@ -0,0 +1,127 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require_relative 'coap_test_helper'
|
3
|
+
|
4
|
+
class TestMessage < Test::Unit::TestCase
|
5
|
+
def test_number_of_bits_up_to
|
6
|
+
assert_equal 0, CoAP.number_of_bits_up_to(1)
|
7
|
+
assert_equal 4, CoAP.number_of_bits_up_to(16)
|
8
|
+
assert_equal 5, CoAP.number_of_bits_up_to(32)
|
9
|
+
assert_equal 7, CoAP.number_of_bits_up_to(128)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_query_encode
|
13
|
+
assert_equal '', CoAP.query_encode([])
|
14
|
+
assert_equal '?', CoAP.query_encode([''])
|
15
|
+
assert_equal '?foo', CoAP.query_encode(['foo'])
|
16
|
+
assert_equal '?foo&bar', CoAP.query_encode(%w(foo bar))
|
17
|
+
assert_equal '?f.o&b-r', CoAP.query_encode(['f.o', 'b-r'])
|
18
|
+
assert_equal '?f(o&b)r', CoAP.query_encode(['f(o', 'b)r'])
|
19
|
+
assert_equal '?foo&b/r', CoAP.query_encode(['foo', 'b/r'])
|
20
|
+
assert_equal '?foo&b%26r', CoAP.query_encode(['foo', 'b&r'])
|
21
|
+
assert_equal '?f%C3%B8o&b%C3%A4r', CoAP.query_encode(['føo', 'bär'])
|
22
|
+
end
|
23
|
+
|
24
|
+
# XXX: now properly checks for trailing slashes, how much trouble?
|
25
|
+
def test_path_decode
|
26
|
+
assert_equal [], CoAP.path_decode('/')
|
27
|
+
assert_equal ['foo'], CoAP.path_decode('/foo')
|
28
|
+
assert_equal ['foo', ''], CoAP.path_decode('/foo/') # confusing!
|
29
|
+
assert_equal %w(foo bar), CoAP.path_decode('/foo/bar')
|
30
|
+
assert_equal ['f.o', 'b-r'], CoAP.path_decode('/f.o/b-r')
|
31
|
+
assert_equal ['f(o', 'b)r'], CoAP.path_decode('/f(o/b)r')
|
32
|
+
assert_equal ['foo', 'b/r'], CoAP.path_decode('/foo/b%2Fr')
|
33
|
+
assert_equal ['foo', 'b&r'], CoAP.path_decode('/foo/b&r')
|
34
|
+
assert_equal ['føo', 'bär'], CoAP.path_decode('/f%C3%B8o/b%C3%A4r')
|
35
|
+
end
|
36
|
+
|
37
|
+
# XXX: now checks for trailing ampersands
|
38
|
+
def test_query_decode
|
39
|
+
assert_equal [], CoAP.query_decode('')
|
40
|
+
assert_equal [''], CoAP.query_decode('?')
|
41
|
+
assert_equal ['foo'], CoAP.query_decode('?foo')
|
42
|
+
assert_equal ['foo', ''], CoAP.query_decode('?foo&')
|
43
|
+
assert_equal %w(foo bar), CoAP.query_decode('?foo&bar')
|
44
|
+
assert_equal ['f.o', 'b-r'], CoAP.query_decode('?f.o&b-r')
|
45
|
+
assert_equal ['f(o', 'b)r'], CoAP.query_decode('?f(o&b)r')
|
46
|
+
assert_equal ['foo', 'b/r'], CoAP.query_decode('?foo&b/r')
|
47
|
+
assert_equal ['foo', 'b&r'], CoAP.query_decode('?foo&b%26r')
|
48
|
+
assert_equal ['føo', 'bär'], CoAP.query_decode('?f%C3%B8o&b%C3%A4r')
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_scheme_and_authority_encode
|
52
|
+
assert_equal 'coap://foo.bar:4711', CoAP.scheme_and_authority_encode('foo.bar', 4711)
|
53
|
+
assert_equal 'coap://foo.bar:4711', CoAP.scheme_and_authority_encode('foo.bar', '4711')
|
54
|
+
assert_raise ArgumentError do
|
55
|
+
CoAP.scheme_and_authority_encode('foo.bar', 'baz')
|
56
|
+
end
|
57
|
+
assert_equal 'coap://bar.baz', CoAP.scheme_and_authority_encode('bar.baz', 5683)
|
58
|
+
assert_equal 'coap://bar.baz', CoAP.scheme_and_authority_encode('bar.baz', '5683')
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_scheme_and_authority_decode
|
62
|
+
assert_equal ['foo.bar', 4711, nil], CoAP.scheme_and_authority_decode('coap://foo.bar:4711')
|
63
|
+
assert_equal ['foo.bar', 5683, nil], CoAP.scheme_and_authority_decode('coap://foo.bar')
|
64
|
+
assert_equal ['foo:bar', 4711, nil], CoAP.scheme_and_authority_decode('coap://[foo:bar]:4711')
|
65
|
+
assert_equal ['foo:bar', 5683, nil], CoAP.scheme_and_authority_decode('coap://%5Bfoo:bar%5D')
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_coap_message
|
69
|
+
input = "\x44\x02\x12\xA0abcd\x41A\x7B.well-known\x04core\x0D\x04rhabarbersaftglas\xFFfoobar".force_encoding('BINARY')
|
70
|
+
output = CoAP.parse(input)
|
71
|
+
w = output.to_wire
|
72
|
+
assert_equal input, w
|
73
|
+
end
|
74
|
+
|
75
|
+
# XXX TODO add token tests
|
76
|
+
|
77
|
+
def test_fenceposting
|
78
|
+
m = CoAP::Message.new(:con, :get, 4711, 'Hello', {})
|
79
|
+
m.options = { max_age: 987_654_321, if_none_match: true }
|
80
|
+
me = m.to_wire
|
81
|
+
m2 = CoAP.parse(me)
|
82
|
+
m.options = CoAP::DEFAULTING_OPTIONS.merge(m.options)
|
83
|
+
assert_equal m2, m
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_fenceposting2
|
87
|
+
m = CoAP::Message.new(:con, :get, 4711, 'Hello', {})
|
88
|
+
m.options = { 4711 => ['foo'], 256 => ['bar'] }
|
89
|
+
me = m.to_wire
|
90
|
+
m2 = CoAP.parse(me)
|
91
|
+
m.options = CoAP::DEFAULTING_OPTIONS.merge(m.options)
|
92
|
+
assert_equal m2, m
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_emptypayload
|
96
|
+
m = CoAP::Message.new(:con, :get, 4711, '', {})
|
97
|
+
m.options = { 4711 => ['foo'], 256 => ['bar'], 65_535 => ['abc' * 100] }
|
98
|
+
me = m.to_wire
|
99
|
+
m2 = CoAP.parse(me)
|
100
|
+
m.options = CoAP::DEFAULTING_OPTIONS.merge(m.options)
|
101
|
+
assert_equal m2, m
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_option_numbers
|
105
|
+
(0...65_536).each do |on|
|
106
|
+
unless CoAP::OPTIONS[on] # those might have special semantics
|
107
|
+
m = CoAP::Message.new(:con, :get, 4711, 'Hello', {})
|
108
|
+
m.options = { on => [''] }
|
109
|
+
me = m.to_wire
|
110
|
+
m2 = CoAP.parse(me)
|
111
|
+
m.options = CoAP::DEFAULTING_OPTIONS.merge(m.options)
|
112
|
+
assert_equal m2, m
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_option_lengths
|
118
|
+
(0...1024).each do |ol|
|
119
|
+
m = CoAP::Message.new(:con, :get, 4711, 'Hello', {})
|
120
|
+
m.options = { 99 => ['x' * ol] }
|
121
|
+
me = m.to_wire
|
122
|
+
m2 = CoAP.parse(me)
|
123
|
+
m.options = CoAP::DEFAULTING_OPTIONS.merge(m.options)
|
124
|
+
assert_equal m2, m
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.13
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carsten Bormann
|
8
|
+
- Simon Frerichs
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.5'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.5'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: resolv-ipv6favor
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: coap \o/ gem.
|
57
|
+
email:
|
58
|
+
- morpheus@morphhome.net
|
59
|
+
executables:
|
60
|
+
- client
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/client
|
71
|
+
- coap.gemspec
|
72
|
+
- lib/coap.rb
|
73
|
+
- lib/coap/block.rb
|
74
|
+
- lib/coap/client.rb
|
75
|
+
- lib/coap/coap.rb
|
76
|
+
- lib/coap/message.rb
|
77
|
+
- lib/coap/mysocket.rb
|
78
|
+
- lib/coap/observer.rb
|
79
|
+
- lib/coap/version.rb
|
80
|
+
- lib/misc/hexdump.rb
|
81
|
+
- test/coap_test_helper.rb
|
82
|
+
- test/disabled_econotag_blck.rb
|
83
|
+
- test/test_client.rb
|
84
|
+
- test/test_message.rb
|
85
|
+
homepage: ''
|
86
|
+
licenses:
|
87
|
+
- TODO
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.2.2
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: coap gem.
|
109
|
+
test_files:
|
110
|
+
- test/coap_test_helper.rb
|
111
|
+
- test/disabled_econotag_blck.rb
|
112
|
+
- test/test_client.rb
|
113
|
+
- test/test_message.rb
|