jruby-openssl 0.2.3 → 0.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of jruby-openssl might be problematic. Click here for more details.

@@ -0,0 +1,177 @@
1
+ module PKCS7Test
2
+ class TestJavaSMIME < Test::Unit::TestCase
3
+ def test_read_pkcs7_should_raise_error_when_parsing_headers_fails
4
+ bio = BIO.new
5
+ mime = Mime.new
6
+ mime.stubs(:parseHeaders).returns(nil)
7
+
8
+ begin
9
+ SMIME.new(mime).readPKCS7(bio, nil)
10
+ assert false
11
+ rescue PKCS7Exception => e
12
+ assert_equal PKCS7::F_SMIME_READ_PKCS7, e.cause.get_method
13
+ assert_equal PKCS7::R_MIME_PARSE_ERROR, e.cause.get_reason
14
+ end
15
+ end
16
+
17
+ def test_read_pkcs7_should_raise_error_when_content_type_is_not_there
18
+ bio = BIO.new
19
+ mime = Mime.new
20
+
21
+ headers = ArrayList.new
22
+ mime.expects(:parseHeaders).with(bio).returns(headers)
23
+ mime.expects(:findHeader).with(headers, "content-type").returns(nil)
24
+
25
+ begin
26
+ SMIME.new(mime).readPKCS7(bio, nil)
27
+ assert false
28
+ rescue PKCS7Exception => e
29
+ assert_equal PKCS7::F_SMIME_READ_PKCS7, e.cause.get_method
30
+ assert_equal PKCS7::R_NO_CONTENT_TYPE, e.cause.get_reason
31
+ end
32
+
33
+
34
+
35
+
36
+ mime = Mime.new
37
+ mime.expects(:parseHeaders).with(bio).returns(headers)
38
+ mime.expects(:findHeader).with(headers, "content-type").returns(MimeHeader.new("content-type", nil))
39
+
40
+ begin
41
+ SMIME.new(mime).readPKCS7(bio, nil)
42
+ assert false
43
+ rescue PKCS7Exception => e
44
+ assert_equal PKCS7::F_SMIME_READ_PKCS7, e.cause.get_method
45
+ assert_equal PKCS7::R_NO_CONTENT_TYPE, e.cause.get_reason
46
+ end
47
+ end
48
+
49
+ def test_read_pkcs7_should_set_the_second_arguments_contents_to_null_if_its_there
50
+ mime = Mime.new
51
+ mime.stubs(:parseHeaders).raises("getOutOfJailForFree")
52
+
53
+ bio2 = BIO.new
54
+ arr = [bio2].to_java BIO
55
+
56
+ begin
57
+ SMIME.new(mime).readPKCS7(nil, arr)
58
+ rescue
59
+ end
60
+
61
+ assert_nil arr[0]
62
+
63
+
64
+ arr = [bio2, bio2].to_java BIO
65
+ begin
66
+ SMIME.new(mime).readPKCS7(nil, arr)
67
+ rescue
68
+ end
69
+
70
+ assert_nil arr[0]
71
+ assert_equal bio2, arr[1]
72
+ end
73
+
74
+ def test_read_pkcs7_should_call_methods_on_mime
75
+ bio = BIO.new
76
+ mime = Mime.new
77
+
78
+ headers = ArrayList.new
79
+ mime.expects(:parseHeaders).with(bio).returns(headers)
80
+ mime.expects(:findHeader).with(headers, "content-type").returns(MimeHeader.new("content-type", "application/pkcs7-mime"))
81
+
82
+ begin
83
+ SMIME.new(mime).readPKCS7(bio, nil)
84
+ rescue java.lang.UnsupportedOperationException
85
+ # This error is expected, since the bio used is not a real one
86
+ end
87
+ end
88
+
89
+ def test_read_pkcs7_throws_correct_exception_if_wrong_content_type
90
+ bio = BIO.new
91
+ mime = Mime.new
92
+
93
+ headers = ArrayList.new
94
+ mime.expects(:parseHeaders).with(bio).returns(headers)
95
+ mime.expects(:findHeader).with(headers, "content-type").returns(MimeHeader.new("content-type", "foo"))
96
+
97
+ begin
98
+ SMIME.new(mime).readPKCS7(bio, nil)
99
+ assert false
100
+ rescue PKCS7Exception => e
101
+ assert_equal PKCS7::F_SMIME_READ_PKCS7, e.cause.get_method
102
+ assert_equal PKCS7::R_INVALID_MIME_TYPE, e.cause.get_reason
103
+ assert_equal "type: foo", e.cause.error_data
104
+ end
105
+ end
106
+
107
+ def test_read_pkcs7_with_multipart_should_fail_if_no_boundary_found
108
+ bio = BIO.new
109
+ mime = Mime.new
110
+
111
+ headers = ArrayList.new
112
+ hdr = MimeHeader.new("content-type", "multipart/signed")
113
+ mime.expects(:parseHeaders).with(bio).returns(headers)
114
+ mime.expects(:findHeader).with(headers, "content-type").returns(hdr)
115
+
116
+ mime.expects(:findParam).with(hdr, "boundary").returns(nil)
117
+
118
+ begin
119
+ SMIME.new(mime).readPKCS7(bio, nil)
120
+ assert false
121
+ rescue PKCS7Exception => e
122
+ assert_equal PKCS7::F_SMIME_READ_PKCS7, e.cause.get_method
123
+ assert_equal PKCS7::R_NO_MULTIPART_BOUNDARY, e.cause.get_reason
124
+ end
125
+ end
126
+
127
+ def test_read_pkcs7_with_multipart_should_fail_if_null_boundary_value
128
+ bio = BIO.new
129
+ mime = Mime.new
130
+
131
+ headers = ArrayList.new
132
+ hdr = MimeHeader.new("content-type", "multipart/signed")
133
+ mime.expects(:parseHeaders).with(bio).returns(headers)
134
+ mime.expects(:findHeader).with(headers, "content-type").returns(hdr)
135
+
136
+ mime.expects(:findParam).with(hdr, "boundary").returns(MimeParam.new("boundary", nil))
137
+
138
+ begin
139
+ SMIME.new(mime).readPKCS7(bio, nil)
140
+ assert false
141
+ rescue PKCS7Exception => e
142
+ assert_equal PKCS7::F_SMIME_READ_PKCS7, e.cause.get_method
143
+ assert_equal PKCS7::R_NO_MULTIPART_BOUNDARY, e.cause.get_reason
144
+ end
145
+ end
146
+
147
+ # TODO: redo this test to be an integration test
148
+ def _test_read_pkcs7_happy_path_without_multipart
149
+ bio = BIO.new
150
+ mime = Mime.new
151
+
152
+ headers = ArrayList.new
153
+ mime.expects(:parseHeaders).with(bio).returns(headers)
154
+ mime.expects(:findHeader).with(headers, "content-type").returns(MimeHeader.new("content-type", "application/pkcs7-mime"))
155
+
156
+ SMIME.new(mime).readPKCS7(bio, nil)
157
+ end
158
+
159
+ def test_read_pkcs7_happy_path_multipart
160
+ bio = BIO::from_string(MultipartSignedString)
161
+ mime = Mime::DEFAULT
162
+ p7 = SMIME.new(mime).readPKCS7(bio, nil)
163
+ end
164
+
165
+ def test_read_pkcs7_happy_path_without_multipart_enveloped
166
+ bio = BIO::from_string(MimeEnvelopedString)
167
+ mime = Mime::DEFAULT
168
+ p7 = SMIME.new(mime).readPKCS7(bio, nil)
169
+ end
170
+
171
+ def test_read_pkcs7_happy_path_without_multipart_signed
172
+ bio = BIO::from_string(MimeSignedString)
173
+ mime = Mime::DEFAULT
174
+ p7 = SMIME.new(mime).readPKCS7(bio, nil)
175
+ end
176
+ end
177
+ end
@@ -1,5 +1,10 @@
1
1
 
2
- require 'java' if RUBY_PLATFORM =~ /java/
2
+ if defined?(JRUBY_VERSION)
3
+ require "java"
4
+ base = File.join(File.dirname(__FILE__), '..')
5
+ $CLASSPATH << File.join(base, 'pkg', 'classes')
6
+ $CLASSPATH << File.join(base, 'lib', 'bcprov-jdk14-139.jar')
7
+ end
3
8
 
4
9
  def protect_require(name)
5
10
  require name
@@ -14,6 +19,7 @@ protect_require 'openssl/test_digest'
14
19
  protect_require 'openssl/test_hmac'
15
20
  protect_require 'openssl/test_ns_spki'
16
21
  protect_require 'openssl/test_pair'
22
+ protect_require 'openssl/test_pkcs7'
17
23
  protect_require 'openssl/test_pkey_rsa'
18
24
  protect_require 'openssl/test_ssl'
19
25
  protect_require 'openssl/test_x509cert'
@@ -23,3 +29,5 @@ protect_require 'openssl/test_x509name'
23
29
  protect_require 'openssl/test_x509req'
24
30
  protect_require 'openssl/test_x509store'
25
31
  protect_require 'test_cipher'
32
+ protect_require 'test_java'
33
+ protect_require 'test_integration'
metadata CHANGED
@@ -44,10 +44,25 @@ files:
44
44
  - lib/openssl/dummyssl.rb
45
45
  - lib/openssl/ssl.rb
46
46
  - lib/openssl/x509.rb
47
+ - test/fixture
47
48
  - test/openssl
49
+ - test/pkcs7_mime_enveloped.message
50
+ - test/pkcs7_mime_signed.message
51
+ - test/pkcs7_multipart_signed.message
52
+ - test/ref
48
53
  - test/test_cipher.rb
54
+ - test/test_integration.rb
55
+ - test/test_java.rb
56
+ - test/test_java_attribute.rb
57
+ - test/test_java_bio.rb
58
+ - test/test_java_mime.rb
59
+ - test/test_java_pkcs7.rb
60
+ - test/test_java_smime.rb
49
61
  - test/test_openssl.rb
50
62
  - test/ut_eof.rb
63
+ - test/fixture/cacert.pem
64
+ - test/fixture/cert_localhost.pem
65
+ - test/fixture/localhost_keypair.pem
51
66
  - test/openssl/ssl_server.rb
52
67
  - test/openssl/test_asn1.rb
53
68
  - test/openssl/test_cipher.rb
@@ -55,6 +70,7 @@ files:
55
70
  - test/openssl/test_hmac.rb
56
71
  - test/openssl/test_ns_spki.rb
57
72
  - test/openssl/test_pair.rb
73
+ - test/openssl/test_pkcs7.rb
58
74
  - test/openssl/test_pkey_rsa.rb
59
75
  - test/openssl/test_ssl.rb
60
76
  - test/openssl/test_x509cert.rb
@@ -64,6 +80,10 @@ files:
64
80
  - test/openssl/test_x509req.rb
65
81
  - test/openssl/test_x509store.rb
66
82
  - test/openssl/utils.rb
83
+ - test/ref/a.out
84
+ - test/ref/compile.rb
85
+ - test/ref/pkcs1
86
+ - test/ref/pkcs1.c
67
87
  required_rubygems_version: !ruby/object:Gem::Requirement
68
88
  requirements:
69
89
  - - '>='
@@ -71,16 +91,24 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
91
  version: !str 0
72
92
  version:
73
93
  extensions: []
74
- rubygems_version: 1.1.1
94
+ rubygems_version: 1.2.0
75
95
  requirements: []
76
96
  authors:
77
97
  - Ola Bini and JRuby contributors
78
- date: 2008-04-30 23:00:00 +00:00
98
+ date: 2008-08-13 22:00:00 +00:00
79
99
  platform: ruby
80
100
  test_files:
101
+ - test/test_cipher.rb
102
+ - test/test_integration.rb
103
+ - test/test_java.rb
104
+ - test/test_java_attribute.rb
105
+ - test/test_java_bio.rb
106
+ - test/test_java_mime.rb
107
+ - test/test_java_pkcs7.rb
108
+ - test/test_java_smime.rb
81
109
  - test/test_openssl.rb
82
110
  version: !ruby/object:Gem::Version
83
- version: 0.2.3
111
+ version: !str 0.3
84
112
  require_paths:
85
113
  - lib
86
114
  dependencies: []