nelumba 0.0.13
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/.gitignore +6 -0
- data/.travis.yml +9 -0
- data/Gemfile +20 -0
- data/README.md +242 -0
- data/Rakefile +7 -0
- data/assets/lotus_logo_purple.png +0 -0
- data/assets/lotus_logo_purple.svg +262 -0
- data/lib/nelumba.rb +47 -0
- data/lib/nelumba/activity.rb +250 -0
- data/lib/nelumba/application.rb +11 -0
- data/lib/nelumba/article.rb +11 -0
- data/lib/nelumba/atom/account.rb +50 -0
- data/lib/nelumba/atom/address.rb +56 -0
- data/lib/nelumba/atom/author.rb +176 -0
- data/lib/nelumba/atom/category.rb +41 -0
- data/lib/nelumba/atom/comment.rb +96 -0
- data/lib/nelumba/atom/entry.rb +216 -0
- data/lib/nelumba/atom/feed.rb +198 -0
- data/lib/nelumba/atom/generator.rb +40 -0
- data/lib/nelumba/atom/link.rb +79 -0
- data/lib/nelumba/atom/name.rb +57 -0
- data/lib/nelumba/atom/organization.rb +62 -0
- data/lib/nelumba/atom/person.rb +179 -0
- data/lib/nelumba/atom/portable_contacts.rb +117 -0
- data/lib/nelumba/atom/source.rb +179 -0
- data/lib/nelumba/atom/thread.rb +60 -0
- data/lib/nelumba/audio.rb +39 -0
- data/lib/nelumba/badge.rb +11 -0
- data/lib/nelumba/binary.rb +52 -0
- data/lib/nelumba/bookmark.rb +30 -0
- data/lib/nelumba/category.rb +49 -0
- data/lib/nelumba/collection.rb +34 -0
- data/lib/nelumba/comment.rb +47 -0
- data/lib/nelumba/crypto.rb +144 -0
- data/lib/nelumba/device.rb +11 -0
- data/lib/nelumba/discover.rb +362 -0
- data/lib/nelumba/event.rb +57 -0
- data/lib/nelumba/feed.rb +173 -0
- data/lib/nelumba/file.rb +43 -0
- data/lib/nelumba/generator.rb +53 -0
- data/lib/nelumba/group.rb +11 -0
- data/lib/nelumba/identity.rb +63 -0
- data/lib/nelumba/image.rb +30 -0
- data/lib/nelumba/link.rb +56 -0
- data/lib/nelumba/note.rb +34 -0
- data/lib/nelumba/notification.rb +229 -0
- data/lib/nelumba/object.rb +251 -0
- data/lib/nelumba/person.rb +306 -0
- data/lib/nelumba/place.rb +34 -0
- data/lib/nelumba/product.rb +30 -0
- data/lib/nelumba/publisher.rb +44 -0
- data/lib/nelumba/question.rb +30 -0
- data/lib/nelumba/review.rb +30 -0
- data/lib/nelumba/service.rb +11 -0
- data/lib/nelumba/subscription.rb +117 -0
- data/lib/nelumba/version.rb +3 -0
- data/lib/nelumba/video.rb +43 -0
- data/nelumba.gemspec +28 -0
- data/spec/activity_spec.rb +116 -0
- data/spec/application_spec.rb +136 -0
- data/spec/article_spec.rb +136 -0
- data/spec/atom/comment_spec.rb +455 -0
- data/spec/atom/feed_spec.rb +684 -0
- data/spec/audio_spec.rb +164 -0
- data/spec/badge_spec.rb +136 -0
- data/spec/binary_spec.rb +218 -0
- data/spec/bookmark.rb +150 -0
- data/spec/collection_spec.rb +152 -0
- data/spec/comment_spec.rb +128 -0
- data/spec/crypto_spec.rb +126 -0
- data/spec/device_spec.rb +136 -0
- data/spec/event_spec.rb +239 -0
- data/spec/feed_spec.rb +252 -0
- data/spec/file_spec.rb +190 -0
- data/spec/group_spec.rb +136 -0
- data/spec/helper.rb +10 -0
- data/spec/identity_spec.rb +67 -0
- data/spec/image_spec.rb +150 -0
- data/spec/link_spec.rb +30 -0
- data/spec/note_spec.rb +163 -0
- data/spec/notification_spec.rb +89 -0
- data/spec/person_spec.rb +244 -0
- data/spec/place_spec.rb +162 -0
- data/spec/product_spec.rb +150 -0
- data/spec/question_spec.rb +156 -0
- data/spec/review_spec.rb +149 -0
- data/spec/service_spec.rb +136 -0
- data/spec/video_spec.rb +164 -0
- data/test/example_feed.atom +393 -0
- data/test/example_feed_empty_author.atom +336 -0
- data/test/example_feed_false_connected.atom +359 -0
- data/test/example_feed_link_without_href.atom +134 -0
- data/test/example_page.html +4 -0
- data/test/mime_type_bug_feed.atom +874 -0
- metadata +288 -0
data/spec/bookmark.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative '../lib/nelumba/bookmark.rb'
|
3
|
+
|
4
|
+
describe Nelumba::Bookmark do
|
5
|
+
describe "#initialize" do
|
6
|
+
it "should store an author" do
|
7
|
+
author = mock('author')
|
8
|
+
Nelumba::Bookmark.new(:author => author).author.must_equal author
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should store the target url" do
|
12
|
+
Nelumba::Bookmark.new(:target_url => "txt").target_url.must_equal "txt"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should store content" do
|
16
|
+
Nelumba::Bookmark.new(:content => "txt").content.must_equal "txt"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should store the published date" do
|
20
|
+
time = mock('date')
|
21
|
+
Nelumba::Bookmark.new(:published => time).published.must_equal time
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should store the updated date" do
|
25
|
+
time = mock('date')
|
26
|
+
Nelumba::Bookmark.new(:updated => time).updated.must_equal time
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should store a display name" do
|
30
|
+
Nelumba::Bookmark.new(:display_name => "url")
|
31
|
+
.display_name.must_equal "url"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should store a summary" do
|
35
|
+
Nelumba::Bookmark.new(:summary => "url").summary.must_equal "url"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should store a url" do
|
39
|
+
Nelumba::Bookmark.new(:url => "url").url.must_equal "url"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should store an id" do
|
43
|
+
Nelumba::Bookmark.new(:uid => "id").uid.must_equal "id"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#to_hash" do
|
48
|
+
it "should contain the content" do
|
49
|
+
Nelumba::Bookmark.new(:content => "Hello")
|
50
|
+
.to_hash[:content].must_equal "Hello"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should contain the author" do
|
54
|
+
author = mock('Nelumba::Person')
|
55
|
+
Nelumba::Bookmark.new(:author => author).to_hash[:author].must_equal author
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should contain the uid" do
|
59
|
+
Nelumba::Bookmark.new(:uid => "Hello").to_hash[:uid].must_equal "Hello"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should contain the target_url" do
|
63
|
+
Nelumba::Bookmark.new(:target_url => "Hello")
|
64
|
+
.to_hash[:target_url].must_equal "Hello"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should contain the url" do
|
68
|
+
Nelumba::Bookmark.new(:url => "Hello").to_hash[:url].must_equal "Hello"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should contain the summary" do
|
72
|
+
Nelumba::Bookmark.new(:summary=> "Hello")
|
73
|
+
.to_hash[:summary].must_equal "Hello"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should contain the display name" do
|
77
|
+
Nelumba::Bookmark.new(:display_name => "Hello")
|
78
|
+
.to_hash[:display_name].must_equal "Hello"
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should contain the published date" do
|
82
|
+
date = mock('Time')
|
83
|
+
Nelumba::Bookmark.new(:published => date).to_hash[:published].must_equal date
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should contain the updated date" do
|
87
|
+
date = mock('Time')
|
88
|
+
Nelumba::Bookmark.new(:updated => date).to_hash[:updated].must_equal date
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#to_json" do
|
93
|
+
before do
|
94
|
+
author = Nelumba::Person.new :display_name => "wilkie"
|
95
|
+
@note = Nelumba::Bookmark.new :content => "Hello",
|
96
|
+
:author => author,
|
97
|
+
:uid => "id",
|
98
|
+
:target_url => "target",
|
99
|
+
:url => "url",
|
100
|
+
:title => "title",
|
101
|
+
:summary => "foo",
|
102
|
+
:display_name => "meh",
|
103
|
+
:published => Time.now,
|
104
|
+
:updated => Time.now
|
105
|
+
|
106
|
+
@json = @note.to_json
|
107
|
+
@data = JSON.parse(@json)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should contain the embedded json for the author" do
|
111
|
+
@data["author"].must_equal JSON.parse(@note.author.to_json)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should contain a 'bookmark' objectType" do
|
115
|
+
@data["objectType"].must_equal "bookmark"
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should contain the id" do
|
119
|
+
@data["id"].must_equal @note.uid
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should contain the target url" do
|
123
|
+
@data["targetUrl"].must_equal @note.target_url
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should contain the content" do
|
127
|
+
@data["content"].must_equal @note.content
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should contain the url" do
|
131
|
+
@data["url"].must_equal @note.url
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should contain the summary" do
|
135
|
+
@data["summary"].must_equal @note.summary
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should contain the display name" do
|
139
|
+
@data["displayName"].must_equal @note.display_name
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should contain the published date as rfc3339" do
|
143
|
+
@data["published"].must_equal @note.published.to_date.rfc3339 + 'Z'
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should contain the updated date as rfc3339" do
|
147
|
+
@data["updated"].must_equal @note.updated.to_date.rfc3339 + 'Z'
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative '../lib/nelumba/collection.rb'
|
3
|
+
|
4
|
+
describe Nelumba::Collection do
|
5
|
+
describe "#initialize" do
|
6
|
+
it "should store content" do
|
7
|
+
Nelumba::Collection.new(:content => "foo").content.must_equal "foo"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should store an author" do
|
11
|
+
author = mock('author')
|
12
|
+
Nelumba::Collection.new(:author => author).author.must_equal author
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should store a summary" do
|
16
|
+
Nelumba::Collection.new(:summary => "url").summary.must_equal "url"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should store a display name" do
|
20
|
+
Nelumba::Collection.new(:display_name => "url")
|
21
|
+
.display_name.must_equal "url"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should store the published date" do
|
25
|
+
time = mock('date')
|
26
|
+
Nelumba::Collection.new(:published => time).published.must_equal time
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should store the updated date" do
|
30
|
+
time = mock('date')
|
31
|
+
Nelumba::Collection.new(:updated => time).updated.must_equal time
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should store a url" do
|
35
|
+
Nelumba::Collection.new(:url => "url").url.must_equal "url"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should store an id" do
|
39
|
+
Nelumba::Collection.new(:uid => "id").uid.must_equal "id"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should store an array of items" do
|
43
|
+
Nelumba::Collection.new(:items => ["foo"]).items.must_equal ["foo"]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should default items to an empty array" do
|
47
|
+
Nelumba::Collection.new.items.must_equal []
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#to_hash" do
|
52
|
+
it "should contain the content" do
|
53
|
+
Nelumba::Collection.new(:content => "Hello")
|
54
|
+
.to_hash[:content].must_equal "Hello"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should contain the author" do
|
58
|
+
author = mock('Nelumba::Person')
|
59
|
+
Nelumba::Collection.new(:author => author).to_hash[:author].must_equal author
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should contain the uid" do
|
63
|
+
Nelumba::Collection.new(:uid => "Hello").to_hash[:uid].must_equal "Hello"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should contain the url" do
|
67
|
+
Nelumba::Collection.new(:url => "Hello").to_hash[:url].must_equal "Hello"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should contain the summary" do
|
71
|
+
Nelumba::Collection.new(:summary => "Hello")
|
72
|
+
.to_hash[:summary].must_equal "Hello"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should contain the display name" do
|
76
|
+
Nelumba::Collection.new(:display_name => "Hello")
|
77
|
+
.to_hash[:display_name].must_equal "Hello"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should contain the published date" do
|
81
|
+
date = mock('Time')
|
82
|
+
Nelumba::Collection.new(:published => date).to_hash[:published].must_equal date
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should contain the updated date" do
|
86
|
+
date = mock('Time')
|
87
|
+
Nelumba::Collection.new(:updated => date).to_hash[:updated].must_equal date
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should contain the array of items" do
|
91
|
+
Nelumba::Collection.new(:items => ["f"]).to_hash[:items].must_equal ["f"]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#to_json" do
|
96
|
+
before do
|
97
|
+
author = Nelumba::Person.new :display_name => "wilkie"
|
98
|
+
@note = Nelumba::Collection.new :items => ["Hello"],
|
99
|
+
:author => author,
|
100
|
+
:uid => "id",
|
101
|
+
:url => "url",
|
102
|
+
:content => "content",
|
103
|
+
:summary => "foo",
|
104
|
+
:display_name => "meh",
|
105
|
+
:published => Time.now,
|
106
|
+
:updated => Time.now
|
107
|
+
|
108
|
+
@json = @note.to_json
|
109
|
+
@data = JSON.parse(@json)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should contain the embedded json for the author" do
|
113
|
+
@data["author"].must_equal JSON.parse(@note.author.to_json)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should contain a 'collection' objectType" do
|
117
|
+
@data["objectType"].must_equal "collection"
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should contain the items" do
|
121
|
+
@data["items"].must_equal JSON.parse(@note.items.to_json)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should contain the id" do
|
125
|
+
@data["id"].must_equal @note.uid
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should contain the content" do
|
129
|
+
@data["content"].must_equal @note.content
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should contain the url" do
|
133
|
+
@data["url"].must_equal @note.url
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should contain the summary" do
|
137
|
+
@data["summary"].must_equal @note.summary
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should contain the display_name" do
|
141
|
+
@data["displayName"].must_equal @note.display_name
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should contain the published date as rfc3339" do
|
145
|
+
@data["published"].must_equal @note.published.to_date.rfc3339 + 'Z'
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should contain the updated date as rfc3339" do
|
149
|
+
@data["updated"].must_equal @note.updated.to_date.rfc3339 + 'Z'
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative '../lib/nelumba/comment.rb'
|
3
|
+
|
4
|
+
describe Nelumba::Comment do
|
5
|
+
describe "#initialize" do
|
6
|
+
it "should store content" do
|
7
|
+
Nelumba::Comment.new(:content => "foo").content.must_equal "foo"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should store an author" do
|
11
|
+
author = mock('author')
|
12
|
+
Nelumba::Comment.new(:author => author).author.must_equal author
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should store the display_name" do
|
16
|
+
Nelumba::Comment.new(:display_name => "Hello").display_name.must_equal "Hello"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should store the published date" do
|
20
|
+
time = mock('date')
|
21
|
+
Nelumba::Comment.new(:published => time).published.must_equal time
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should store the updated date" do
|
25
|
+
time = mock('date')
|
26
|
+
Nelumba::Comment.new(:updated => time).updated.must_equal time
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should store a url" do
|
30
|
+
Nelumba::Comment.new(:url => "url").url.must_equal "url"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should store an id" do
|
34
|
+
Nelumba::Comment.new(:uid => "id").uid.must_equal "id"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#to_hash" do
|
39
|
+
it "should contain the content" do
|
40
|
+
Nelumba::Comment.new(:content => "Hello").to_hash[:content].must_equal "Hello"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should contain the author" do
|
44
|
+
author = mock('Nelumba::Person')
|
45
|
+
Nelumba::Comment.new(:author => author).to_hash[:author].must_equal author
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should contain the uid" do
|
49
|
+
Nelumba::Comment.new(:uid => "Hello").to_hash[:uid].must_equal "Hello"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should contain the url" do
|
53
|
+
Nelumba::Comment.new(:url => "Hello").to_hash[:url].must_equal "Hello"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should contain the display_name" do
|
57
|
+
Nelumba::Comment.new(:display_name => "Hello")
|
58
|
+
.to_hash[:display_name].must_equal "Hello"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should contain the published date" do
|
62
|
+
date = mock('Time')
|
63
|
+
Nelumba::Comment.new(:published => date).to_hash[:published].must_equal date
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should contain the updated date" do
|
67
|
+
date = mock('Time')
|
68
|
+
Nelumba::Comment.new(:updated => date).to_hash[:updated].must_equal date
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#to_json" do
|
73
|
+
before do
|
74
|
+
author = Nelumba::Person.new :display_name => "wilkie"
|
75
|
+
@note = Nelumba::Comment.new :content => "Hello",
|
76
|
+
:author => author,
|
77
|
+
:summary => "foo",
|
78
|
+
:display_name => "Foo",
|
79
|
+
:uid => "id",
|
80
|
+
:url => "url",
|
81
|
+
:published => Time.now,
|
82
|
+
:updated => Time.now
|
83
|
+
|
84
|
+
@json = @note.to_json
|
85
|
+
@data = JSON.parse(@json)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should contain the embedded json for the author" do
|
89
|
+
@data["author"].must_equal JSON.parse(@note.author.to_json)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should contain a 'comment' objectType" do
|
93
|
+
@data["objectType"].must_equal "comment"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should contain the id" do
|
97
|
+
@data["id"].must_equal @note.uid
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should contain the content" do
|
101
|
+
@data["content"].must_equal @note.content
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should contain the displayName" do
|
105
|
+
@data["displayName"].must_equal @note.display_name
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should contain the summary" do
|
109
|
+
@data["summary"].must_equal @note.summary
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should contain the display name" do
|
113
|
+
@data["displayName"].must_equal @note.display_name
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should contain the url" do
|
117
|
+
@data["url"].must_equal @note.url
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should contain the published date as rfc3339" do
|
121
|
+
@data["published"].must_equal @note.published.to_date.rfc3339 + 'Z'
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should contain the updated date as rfc3339" do
|
125
|
+
@data["updated"].must_equal @note.updated.to_date.rfc3339 + 'Z'
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/spec/crypto_spec.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative '../lib/nelumba/crypto.rb'
|
3
|
+
|
4
|
+
describe Nelumba::Crypto do
|
5
|
+
# To make things faster, we can stub key generation:
|
6
|
+
# But we will _actually_ generate one good key for the test run
|
7
|
+
before do
|
8
|
+
$__key ||= RSA::KeyPair.generate(2048)
|
9
|
+
RSA::KeyPair.stubs(:generate).returns($__key)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "new_keypair" do
|
13
|
+
it "should return a KeyPair structure" do
|
14
|
+
Nelumba::Crypto.new_keypair.class.must_equal Nelumba::Crypto::KeyPair
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return a KeyPair structure with an RSA public key" do
|
18
|
+
Nelumba::Crypto.new_keypair.public_key.must_match /^RSA\.(.*?)\.(.*)$/
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return a KeyPair structure with an RSA private key" do
|
22
|
+
Nelumba::Crypto.new_keypair.private_key.must_match /^RSA\.(.*?)\.(.*)$/
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should relegate to RSA::KeyPair" do
|
26
|
+
ret = RSA::KeyPair.generate(4)
|
27
|
+
RSA::KeyPair.expects(:generate).returns(ret)
|
28
|
+
|
29
|
+
Nelumba::Crypto.new_keypair
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "emsa_sign" do
|
34
|
+
it "should return a string with the EMSA prefix" do
|
35
|
+
keypair = Nelumba::Crypto.new_keypair
|
36
|
+
|
37
|
+
sequence = "^\x00\x01\xFF*?\x00\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01\x05\x00\x04\x20"
|
38
|
+
matcher = Regexp.new(sequence, nil, 'n')
|
39
|
+
|
40
|
+
RSA::KeyPair.any_instance.expects(:decrypt).with(regexp_matches(matcher))
|
41
|
+
|
42
|
+
Nelumba::Crypto.emsa_sign "payload", keypair.private_key
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return the result of decryption with the private key" do
|
46
|
+
keypair = Nelumba::Crypto.new_keypair
|
47
|
+
|
48
|
+
# This is a heavily implementation driven test to avoid testing RSA
|
49
|
+
|
50
|
+
Nelumba::Crypto.stubs(:generate_key).with(keypair.private_key).returns("keypair")
|
51
|
+
Nelumba::Crypto.stubs(:emsa_signature).with("payload", "keypair").returns("signature")
|
52
|
+
Nelumba::Crypto.stubs(:decrypt).with("keypair", "signature").returns("DECRYPTED")
|
53
|
+
|
54
|
+
Nelumba::Crypto.emsa_sign("payload", keypair.private_key)
|
55
|
+
.must_equal "DECRYPTED"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should end the signature with the SHA2 of the plaintext" do
|
59
|
+
keypair = Nelumba::Crypto.new_keypair
|
60
|
+
|
61
|
+
Digest::SHA2.any_instance.expects(:digest)
|
62
|
+
.with("payload")
|
63
|
+
.returns("SHA2")
|
64
|
+
|
65
|
+
matcher = /\x20SHA2$/
|
66
|
+
RSA::KeyPair.any_instance.expects(:decrypt).with(regexp_matches(matcher))
|
67
|
+
|
68
|
+
Nelumba::Crypto.emsa_sign("payload", keypair.private_key)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "emsa_verify" do
|
73
|
+
it "should return true when the message matches" do
|
74
|
+
keypair = Nelumba::Crypto.new_keypair
|
75
|
+
|
76
|
+
signature = Nelumba::Crypto.emsa_sign("payload", keypair.private_key)
|
77
|
+
|
78
|
+
Nelumba::Crypto.emsa_verify("payload", signature, keypair.public_key)
|
79
|
+
.must_equal true
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return false when the message does not match" do
|
83
|
+
keypair = Nelumba::Crypto.new_keypair
|
84
|
+
|
85
|
+
bogus_signature =
|
86
|
+
"\x00\x01\x00\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01\x05\x00\x04\x20BOGUS"
|
87
|
+
|
88
|
+
bogus_signature.force_encoding('binary')
|
89
|
+
|
90
|
+
signature = Nelumba::Crypto.emsa_sign("payload", keypair.private_key)
|
91
|
+
|
92
|
+
RSA::KeyPair.any_instance.expects(:encrypt)
|
93
|
+
.with(signature)
|
94
|
+
.returns(bogus_signature)
|
95
|
+
|
96
|
+
Nelumba::Crypto.emsa_verify("payload", signature, keypair.public_key)
|
97
|
+
.must_equal false
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "decrypt" do
|
102
|
+
it "should relegate to RSA::KeyPair" do
|
103
|
+
keypair = Nelumba::Crypto.new_keypair
|
104
|
+
|
105
|
+
RSA::KeyPair.any_instance.expects(:decrypt)
|
106
|
+
.with("payload")
|
107
|
+
.returns("OBSCURED")
|
108
|
+
|
109
|
+
Nelumba::Crypto.decrypt(keypair.private_key, "payload")
|
110
|
+
.must_equal "OBSCURED"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "encrypt" do
|
115
|
+
it "should relegate to RSA::KeyPair" do
|
116
|
+
keypair = Nelumba::Crypto.new_keypair
|
117
|
+
|
118
|
+
RSA::KeyPair.any_instance.expects(:encrypt)
|
119
|
+
.with("payload")
|
120
|
+
.returns("OBSCURED")
|
121
|
+
|
122
|
+
Nelumba::Crypto.encrypt(keypair.public_key, "payload")
|
123
|
+
.must_equal "OBSCURED"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|