ordo 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/CHANGES.md +7 -0
- data/README.md +1 -0
- data/lib/ordo.rb +1 -1
- data/lib/ordo/message/parser.rb +9 -1
- data/lib/ordo/version.rb +2 -2
- data/spec/ordo/message/parser_spec.rb +52 -29
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04e607b11a82dde05b1b45e926adb043c9fb11f4
|
4
|
+
data.tar.gz: 002a998c4afb7e42ae674ab7c58bd1d48e9a1a15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee6e1a1b1f838553726948af3fc34f2befa61df9d1ceb701c8027b315252bc867dc2f2a6497569f86d11ceac7b0f3694e15c5edf77fdf9f976b1d85bb3b53cb2
|
7
|
+
data.tar.gz: 709ed72d6d3f65028562aa59a28f57f22c647ff5af04d67f7aa56eb6c77806c01ac404185490524d0dfd915d6d60d6d7d58e3ee4ab70309779ecb3b07b247235
|
data/CHANGES.md
ADDED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|

|
2
2
|
=========================================================
|
3
3
|
|
4
|
+
[](http://rubygems.org/gems/ordo)
|
4
5
|
[](https://travis-ci.org/cryptosphere/ordo)
|
5
6
|
[](https://codeclimate.com/github/cryptosphere/ordo)
|
6
7
|
[![Coverage
|
data/lib/ordo.rb
CHANGED
data/lib/ordo/message/parser.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'strscan'
|
4
|
+
require 'base64'
|
4
5
|
|
5
6
|
module ORDO
|
6
7
|
class Message
|
@@ -70,7 +71,14 @@ module ORDO
|
|
70
71
|
end
|
71
72
|
|
72
73
|
def parse_body
|
73
|
-
|
74
|
+
raw_body = @scanner.rest
|
75
|
+
encoding = @fields['Content-Transfer-Encoding']
|
76
|
+
|
77
|
+
@body = case encoding
|
78
|
+
when 'base64' then Base64.strict_decode64(raw_body)
|
79
|
+
when 'binary', NilClass then raw_body
|
80
|
+
else fail ArgumentError, "invalid message encoding: #{encoding}"
|
81
|
+
end
|
74
82
|
end
|
75
83
|
|
76
84
|
def parse_error(message)
|
data/lib/ordo/version.rb
CHANGED
@@ -17,46 +17,69 @@ describe ORDO::Message::Parser do
|
|
17
17
|
let(:example_body) { 'Some things are better left unread' }
|
18
18
|
let(:example_message) { example_header + example_body }
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
let(:example_header64) { example_header.sub('binary', 'base64') }
|
21
|
+
let(:example_body64) { Base64.strict_encode64(example_body) }
|
22
|
+
let(:example_message64) { example_header64 + example_body64 }
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
'Content-Length' => example_body.length.to_s,
|
27
|
-
'Content-Transfer-Encoding' => example_encoding
|
28
|
-
)
|
24
|
+
context 'binary encoding' do
|
25
|
+
it 'parses messages' do
|
26
|
+
parser = subject.parse(example_message)
|
29
27
|
|
30
|
-
|
31
|
-
|
28
|
+
expect(parser.version).to eq example_version
|
29
|
+
expect(parser.fields).to eq(
|
30
|
+
'Cipher' => example_cipher,
|
31
|
+
'Content-Length' => example_body.length.to_s,
|
32
|
+
'Content-Transfer-Encoding' => example_encoding
|
33
|
+
)
|
32
34
|
|
33
|
-
|
34
|
-
begin
|
35
|
-
subject.parse('garbage')
|
36
|
-
rescue ORDO::ParseError => ex # rubocop:disable all
|
35
|
+
expect(parser.body).to eq example_body
|
37
36
|
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'base64 encoding' do
|
40
|
+
it 'parses messages' do
|
41
|
+
parser = subject.parse(example_message64)
|
38
42
|
|
39
|
-
|
40
|
-
|
43
|
+
expect(parser.version).to eq example_version
|
44
|
+
expect(parser.fields).to eq(
|
45
|
+
'Cipher' => example_cipher,
|
46
|
+
'Content-Length' => example_body.length.to_s,
|
47
|
+
'Content-Transfer-Encoding' => 'base64'
|
48
|
+
)
|
49
|
+
|
50
|
+
expect(parser.body).to eq example_body
|
51
|
+
end
|
41
52
|
end
|
42
53
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
54
|
+
context 'parse errors' do
|
55
|
+
it 'raises ParseError if no ORDO MSG header found' do
|
56
|
+
begin
|
57
|
+
subject.parse('garbage')
|
58
|
+
rescue ORDO::ParseError => ex # rubocop:disable all
|
59
|
+
end
|
60
|
+
|
61
|
+
expect(ex).to be_a ORDO::ParseError
|
62
|
+
expect(ex.to_s).to match(/no.*header/)
|
47
63
|
end
|
48
64
|
|
49
|
-
|
50
|
-
|
51
|
-
|
65
|
+
it 'raises ParseError if version is invalid' do
|
66
|
+
begin
|
67
|
+
subject.parse('---ORDO MSG vX---')
|
68
|
+
rescue ORDO::ParseError => ex # rubocop:disable all
|
69
|
+
end
|
52
70
|
|
53
|
-
|
54
|
-
|
55
|
-
subject.parse("---ORDO MSG v0---\r\nfoo: bar\r\n\r\n")
|
56
|
-
rescue ORDO::ParseError => ex # rubocop:disable all
|
71
|
+
expect(ex).to be_a ORDO::ParseError
|
72
|
+
expect(ex.to_s).to match(/invalid version/)
|
57
73
|
end
|
58
74
|
|
59
|
-
|
60
|
-
|
75
|
+
it 'raises ParseError if invalid fields are encountered' do
|
76
|
+
begin
|
77
|
+
subject.parse("---ORDO MSG v0---\r\nfoo: bar\r\n\r\n")
|
78
|
+
rescue ORDO::ParseError => ex # rubocop:disable all
|
79
|
+
end
|
80
|
+
|
81
|
+
expect(ex).to be_a ORDO::ParseError
|
82
|
+
expect(ex.to_s).to match(/invalid.*field name/)
|
83
|
+
end
|
61
84
|
end
|
62
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ordo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- ".rspec"
|
78
78
|
- ".rubocop.yml"
|
79
79
|
- ".travis.yml"
|
80
|
+
- CHANGES.md
|
80
81
|
- Gemfile
|
81
82
|
- Guardfile
|
82
83
|
- LICENSE.txt
|