|
| 1 | +require_relative '../../../../library/digest/sha1/shared/constants' |
| 2 | +require_relative '../../../../library/digest/sha256/shared/constants' |
| 3 | +require_relative '../../../../library/digest/sha384/shared/constants' |
| 4 | +require_relative '../../../../library/digest/sha512/shared/constants' |
| 5 | +require 'openssl' |
| 6 | + |
| 7 | +describe :openssl_digest_update, shared: true do |
| 8 | + context "it supports full data chunks" do |
| 9 | + it "returns a SHA1 digest" do |
| 10 | + digest = OpenSSL::Digest.new('sha1') |
| 11 | + digest.send(@method, SHA1Constants::Contents) |
| 12 | + digest.digest.should == SHA1Constants::Digest |
| 13 | + end |
| 14 | + |
| 15 | + it "returns a SHA256 digest" do |
| 16 | + digest = OpenSSL::Digest.new('sha256') |
| 17 | + digest.send(@method, SHA256Constants::Contents) |
| 18 | + digest.digest.should == SHA256Constants::Digest |
| 19 | + end |
| 20 | + |
| 21 | + it "returns a SHA384 digest" do |
| 22 | + digest = OpenSSL::Digest.new('sha384') |
| 23 | + digest.send(@method, SHA384Constants::Contents) |
| 24 | + digest.digest.should == SHA384Constants::Digest |
| 25 | + end |
| 26 | + |
| 27 | + it "returns a SHA512 digest" do |
| 28 | + digest = OpenSSL::Digest.new('sha512') |
| 29 | + digest.send(@method, SHA512Constants::Contents) |
| 30 | + digest.digest.should == SHA512Constants::Digest |
| 31 | + end |
| 32 | + end |
| 33 | + |
| 34 | + context "it support smaller chunks" do |
| 35 | + it "returns a SHA1 digest" do |
| 36 | + digest = OpenSSL::Digest.new('sha1') |
| 37 | + SHA1Constants::Contents.each_char { |b| digest.send(@method, b) } |
| 38 | + digest.digest.should == SHA1Constants::Digest |
| 39 | + end |
| 40 | + |
| 41 | + it "returns a SHA256 digest" do |
| 42 | + digest = OpenSSL::Digest.new('sha256') |
| 43 | + SHA256Constants::Contents.each_char { |b| digest.send(@method, b) } |
| 44 | + digest.digest.should == SHA256Constants::Digest |
| 45 | + end |
| 46 | + |
| 47 | + it "returns a SHA384 digest" do |
| 48 | + digest = OpenSSL::Digest.new('sha384') |
| 49 | + SHA384Constants::Contents.each_char { |b| digest.send(@method, b) } |
| 50 | + digest.digest.should == SHA384Constants::Digest |
| 51 | + end |
| 52 | + |
| 53 | + it "returns a SHA512 digest" do |
| 54 | + digest = OpenSSL::Digest.new('sha512') |
| 55 | + SHA512Constants::Contents.each_char { |b| digest.send(@method, b) } |
| 56 | + digest.digest.should == SHA512Constants::Digest |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + context "it converts input using #to_str" do |
| 61 | + it "returns a SHA1 digest" do |
| 62 | + str = mock('str') |
| 63 | + str.should_receive(:to_str).and_return(SHA1Constants::Contents) |
| 64 | + digest = OpenSSL::Digest.new('sha1') |
| 65 | + digest.send(@method, str) |
| 66 | + digest.digest.should == SHA1Constants::Digest |
| 67 | + end |
| 68 | + |
| 69 | + it "returns a SHA256 digest" do |
| 70 | + str = mock('str') |
| 71 | + str.should_receive(:to_str).and_return(SHA256Constants::Contents) |
| 72 | + digest = OpenSSL::Digest.new('sha256') |
| 73 | + digest.send(@method, str) |
| 74 | + digest.digest.should == SHA256Constants::Digest |
| 75 | + end |
| 76 | + |
| 77 | + it "returns a SHA384 digest" do |
| 78 | + str = mock('str') |
| 79 | + str.should_receive(:to_str).and_return(SHA384Constants::Contents) |
| 80 | + digest = OpenSSL::Digest.new('sha384') |
| 81 | + digest.send(@method, str) |
| 82 | + digest.digest.should == SHA384Constants::Digest |
| 83 | + end |
| 84 | + |
| 85 | + it "returns a SHA512 digest" do |
| 86 | + str = mock('str') |
| 87 | + str.should_receive(:to_str).and_return(SHA512Constants::Contents) |
| 88 | + digest = OpenSSL::Digest.new('sha512') |
| 89 | + digest.send(@method, str) |
| 90 | + digest.digest.should == SHA512Constants::Digest |
| 91 | + end |
| 92 | + end |
| 93 | + |
| 94 | + context "it raises a TypeError for input that cannot be coerced into a String" do |
| 95 | + it "raises a TypeError with SHA1" do |
| 96 | + digest = OpenSSL::Digest.new('sha1') |
| 97 | + -> { |
| 98 | + digest.send(@method, Object.new) |
| 99 | + }.should raise_error(TypeError, 'no implicit conversion of Object into String') |
| 100 | + end |
| 101 | + |
| 102 | + it "raises a TypeError with SHA256" do |
| 103 | + digest = OpenSSL::Digest.new('sha256') |
| 104 | + -> { |
| 105 | + digest.send(@method, Object.new) |
| 106 | + }.should raise_error(TypeError, 'no implicit conversion of Object into String') |
| 107 | + end |
| 108 | + |
| 109 | + it "raises a TypeError with SHA384" do |
| 110 | + digest = OpenSSL::Digest.new('sha384') |
| 111 | + -> { |
| 112 | + digest.send(@method, Object.new) |
| 113 | + }.should raise_error(TypeError, 'no implicit conversion of Object into String') |
| 114 | + end |
| 115 | + |
| 116 | + it "raises a TypeError with SHA512" do |
| 117 | + digest = OpenSSL::Digest.new('sha512') |
| 118 | + -> { |
| 119 | + digest.send(@method, Object.new) |
| 120 | + }.should raise_error(TypeError, 'no implicit conversion of Object into String') |
| 121 | + end |
| 122 | + end |
| 123 | +end |
0 commit comments