forked from stesla/base32
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from cheerful/ruby-2.4-and-above-support
Ruby 2.4+ Support
- Loading branch information
Showing
6 changed files
with
86 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
sudo: false | ||
language: ruby | ||
rvm: | ||
- 1.8.7 | ||
- ree | ||
- 1.9.2 | ||
- 1.9.3-p551 | ||
- 2.0.0-p598 | ||
- 2.1.0 | ||
- 2.1.5 | ||
- 2.2.0 | ||
- 2.2.1 | ||
- 2.2.1-clang | ||
- 2.4.3 | ||
- 2.5.5 | ||
- 2.6.2 | ||
- ruby-head | ||
- ruby-head-clang | ||
- jruby-19mode | ||
- jruby-head | ||
bundler_args: --binstubs rake | ||
notifications: | ||
recipients: | ||
- thomas@slash7.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# encoding: utf-8 | ||
class URLcryptRegressionTest < TestClass | ||
def test_encryption_and_decryption | ||
original = '{"some":"json_data","token":"dfsfsdfsdf"}' | ||
encrypted = URLcrypt.encrypt(original) | ||
|
||
encrypted = URLcrypt::encrypt(original) | ||
assert_equal(URLcrypt::decrypt(encrypted), original) | ||
end | ||
|
||
def test_encryption_with_too_long_key | ||
# this key was generated via rake secret in a rails app, the pack() converts it into a byte array | ||
secret = ['d25883a27b9a639da85ea7e159b661218799c9efa63069fac13a6778c954fb6d721968887a19bdb01af8f59eb5a90d256bd9903355c20b0b4b39bf4048b9b17b'].pack('H*') | ||
URLcrypt::key = secret | ||
|
||
assert OpenSSL::Cipher.new('aes-256-cbc').key_len < secret.bytesize | ||
|
||
original = "hello world!" | ||
encrypted = URLcrypt::encrypt(original) | ||
assert_equal(URLcrypt::decrypt(encrypted), original) | ||
end | ||
|
||
def test_encryption_and_decryption_with_too_long_key | ||
# this key was generated via rake secret in a rails app, the pack() converts it into a byte array | ||
secret = ['d25883a27b9a639da85ea7e159b661218799c9efa63069fac13a6778c954fb6d721968887a19bdb01af8f59eb5a90d256bd9903355c20b0b4b39bf4048b9b17b'].pack('H*') | ||
URLcrypt::key = secret | ||
|
||
assert OpenSSL::Cipher.new('aes-256-cbc').key_len < secret.bytesize | ||
|
||
original = '{"some":"json_data","token":"dfsfsdfsdf"}' | ||
encrypted = URLcrypt.encrypt(original) | ||
|
||
encrypted = URLcrypt::encrypt(original) | ||
assert_equal(URLcrypt::decrypt(encrypted), original) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# encoding: utf-8 | ||
require 'bundler' | ||
Bundler.require(:default, :test) | ||
|
||
require 'coveralls' | ||
Coveralls.wear! | ||
|
||
require 'test/unit' | ||
|
||
class TestClass < Test::Unit::TestCase | ||
require 'URLcrypt' | ||
|
||
def assert_bytes_equal(string1, string2) | ||
bytes1 = string1.bytes.to_a.join(':') | ||
bytes2 = string2.bytes.to_a.join(':') | ||
assert_equal(bytes1, bytes2) | ||
end | ||
|
||
def assert_decoding(encoded, plain) | ||
decoded = URLcrypt.decode(encoded) | ||
assert_bytes_equal(plain, decoded) | ||
end | ||
|
||
def assert_encoding(encoded, plain) | ||
actual = URLcrypt.encode(plain) | ||
assert_bytes_equal(encoded, actual) | ||
end | ||
|
||
def assert_encode_and_decode(encoded, plain) | ||
assert_encoding(encoded, plain) | ||
assert_decoding(encoded, plain) | ||
end | ||
end |