From 61029d9070f4bf2f7c83a8d3c1a25b09421c888d Mon Sep 17 00:00:00 2001 From: flower-pot Date: Sun, 14 Jun 2015 20:18:45 +0200 Subject: [PATCH 1/9] start testing with jruby --- .travis.yml | 5 ++++- spec/client/secret_spec.rb | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 947f241..82d4c25 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,11 @@ language: ruby rvm: -- 2.2.2 + - ruby-head + - jruby-head sudo: false cache: bundler +env: + - JRUBY_OPTS="-J-Dfile.encoding=UTF-8 -Xcli.debug=true --debug" deploy: provider: rubygems api_key: diff --git a/spec/client/secret_spec.rb b/spec/client/secret_spec.rb index 3ab4d62..e2840a7 100644 --- a/spec/client/secret_spec.rb +++ b/spec/client/secret_spec.rb @@ -1,3 +1,5 @@ +# encoding: UTF-8 + RSpec.describe Duse::Client::Secret do before :each do Duse.config = Duse::CLIConfig.new({ 'uri' => 'https://example.com/'}) From a3ab4b47ba62eb6fec9d6e0315fc2f18ab3fbd35 Mon Sep 17 00:00:00 2001 From: flower-pot Date: Sun, 14 Jun 2015 20:31:51 +0200 Subject: [PATCH 2/9] no need for extra opts --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 82d4c25..f3bf4d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,6 @@ rvm: - jruby-head sudo: false cache: bundler -env: - - JRUBY_OPTS="-J-Dfile.encoding=UTF-8 -Xcli.debug=true --debug" deploy: provider: rubygems api_key: From 85deaa90d4775c482725656e262f67b424cd07ec Mon Sep 17 00:00:00 2001 From: flower-pot Date: Sun, 14 Jun 2015 22:22:31 +0200 Subject: [PATCH 3/9] test with jruby more exhaustively --- .travis.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f3bf4d3..ad6b941 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,19 @@ language: ruby rvm: - - ruby-head - - jruby-head + - 2.2.2 + - jruby-1.7.19 +jdk: + - openjdk7 + - oraclejdk7 + - oraclejdk8 +matrix: + exclude: + - rvm: 2.2.2 + jdk: oraclejdk7 + - rvm: 2.2.2 + jdk: oraclejdk8 +env: + - JRUBY_OPTS="-Xcli.debug=true --debug" sudo: false cache: bundler deploy: From 871f4967a40fb09a7a622a38e36ee36c12d046f3 Mon Sep 17 00:00:00 2001 From: flower-pot Date: Sun, 14 Jun 2015 22:29:02 +0200 Subject: [PATCH 4/9] add note about JCE --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 69e15e6..ea9287b 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,17 @@ written in ruby. This implementation was heavily inspired by [travis-ci/travis.rb](https://github.com/travis-ci/travis.rb) +Compatibility +------------- + +Tested against + +* Ruby MRI +* JRuby + +> Hint: Be sure to install the Java Cryptography Extension (JCE) Unlimited +> Strength Jurisdiction Policy Files for this to work on the JVM + CLI === From 1d4f9e82ad9f353f382c3b524dc2c97c6cb4b329 Mon Sep 17 00:00:00 2001 From: flower-pot Date: Mon, 15 Jun 2015 17:38:44 +0200 Subject: [PATCH 5/9] use the engine specific key string representation --- spec/client/user_spec.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/client/user_spec.rb b/spec/client/user_spec.rb index 36a12ca..19db68e 100644 --- a/spec/client/user_spec.rb +++ b/spec/client/user_spec.rb @@ -33,19 +33,19 @@ def stub_create_user describe '.create' do it 'creates correct user entity from json create response' do stub_create_user - public_key = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCftZvHkB6uKWVDvrIzmy2p496H\nv9PD/hhRk+DSXcE/CPtRmvYZzbWbbBup9hkvhyH/P1O5EF8KSZm4Cdnz6p37idTe\nNdlaH9cRFV2wc2A/hbg2kaISxrDxUqRbywBE9NOBSjXu2wRpy0TMo85eM2A0E2ET\n2XM6tZcuwFULX6bl8QIDAQAB\n-----END PUBLIC KEY-----\n" + public_key = OpenSSL::PKey::RSA.new("-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCftZvHkB6uKWVDvrIzmy2p496H\nv9PD/hhRk+DSXcE/CPtRmvYZzbWbbBup9hkvhyH/P1O5EF8KSZm4Cdnz6p37idTe\nNdlaH9cRFV2wc2A/hbg2kaISxrDxUqRbywBE9NOBSjXu2wRpy0TMo85eM2A0E2ET\n2XM6tZcuwFULX6bl8QIDAQAB\n-----END PUBLIC KEY-----\n") user = Duse::User.create( username: 'flower-pot', email: 'flower-pot@example.org', password: 'Passw0rd!', password_confirmation: 'Passw0rd!', - public_key: public_key + public_key: public_key.to_s ) expect(user.username).to eq 'flower-pot' expect(user.email).to eq 'flower-pot@example.org' - expect(user.public_key.to_s).to eq public_key + expect(user.public_key.to_s).to eq public_key.to_s end end @@ -53,39 +53,39 @@ def stub_create_user context 'own user' do it 'creates the correct entity when requesting own user' do stub_user_me_get - public_key = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmMm3Ovh7gU0rLHK4NiHh\nWaYRrV9PH6XtHqV0GoiHH7awrjVkT1aZiS+nlBxckfuvuQjRXakVCZh18UdQadVQ\n7FLTWMZNoZ/uh41g4Iv17Wh1I3Fgqihdm83cSWvJ81qQCVGBaKeVitSa49zT/Mmo\noBvYFwulaqJjhqFc3862Rl3WowzGVqGf+OiYhFrBbnIqXijDmVKsbqkG5AILGo1n\nng06HIAvMqUcGMebgoju9SuKaR+C46KT0K5sPpNw/tNcDEZqZAd25QjAroGnpRHS\nI9hTEuPopPSyRqz/EVQfbhi0LbkdDW9S5ECw7GfFPFpRp2239fjl/9ybL6TkeZL7\nAwIDAQAB\n-----END PUBLIC KEY-----\n" + public_key = OpenSSL::PKey::RSA.new("-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmMm3Ovh7gU0rLHK4NiHh\nWaYRrV9PH6XtHqV0GoiHH7awrjVkT1aZiS+nlBxckfuvuQjRXakVCZh18UdQadVQ\n7FLTWMZNoZ/uh41g4Iv17Wh1I3Fgqihdm83cSWvJ81qQCVGBaKeVitSa49zT/Mmo\noBvYFwulaqJjhqFc3862Rl3WowzGVqGf+OiYhFrBbnIqXijDmVKsbqkG5AILGo1n\nng06HIAvMqUcGMebgoju9SuKaR+C46KT0K5sPpNw/tNcDEZqZAd25QjAroGnpRHS\nI9hTEuPopPSyRqz/EVQfbhi0LbkdDW9S5ECw7GfFPFpRp2239fjl/9ybL6TkeZL7\nAwIDAQAB\n-----END PUBLIC KEY-----\n") user = Duse::User.find 'me' expect(user.username).to eq 'flower-pot' expect(user.email).to eq 'flower-pot@example.org' - expect(user.public_key.to_s).to eq public_key + expect(user.public_key.to_s).to eq public_key.to_s end end context 'server user' do it 'creates the correct entity when requesting the server user' do stub_server_user_get - public_key = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvyvyAf7lnVx9eQcAS7JL\nYRHrqJJe51rAdanaUiiy8eek2Iyh6JG551EK7x4n9/Y7r0fW2sNmy+Bp3FpL8E/p\ncxutggTWCnUQUvXmEEm5qZ1KOIIlEQNp5glToAenJ7pxotJsTMlVw4tizsKScenc\n8w+02wpcmWuzWKjoY/G5KV33UDz/LxVo1RJdJp94JiL/OinIl+uk+Vf7VZj/E8g/\n7DyXIuiBosVpj9E9T4kpxs3/7RmUfDzUisVq0UvgflRjvP1V+1KdpNnjVB+H08mb\nSVO6yf2YOcrPDRa3pgz7PIr225QJ+HmVjPTg5VAy7rUxhCK+q+HNd2oz35zA70SO\npQIDAQAB\n-----END PUBLIC KEY-----\n" + public_key = OpenSSL::PKey::RSA.new("-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvyvyAf7lnVx9eQcAS7JL\nYRHrqJJe51rAdanaUiiy8eek2Iyh6JG551EK7x4n9/Y7r0fW2sNmy+Bp3FpL8E/p\ncxutggTWCnUQUvXmEEm5qZ1KOIIlEQNp5glToAenJ7pxotJsTMlVw4tizsKScenc\n8w+02wpcmWuzWKjoY/G5KV33UDz/LxVo1RJdJp94JiL/OinIl+uk+Vf7VZj/E8g/\n7DyXIuiBosVpj9E9T4kpxs3/7RmUfDzUisVq0UvgflRjvP1V+1KdpNnjVB+H08mb\nSVO6yf2YOcrPDRa3pgz7PIr225QJ+HmVjPTg5VAy7rUxhCK+q+HNd2oz35zA70SO\npQIDAQAB\n-----END PUBLIC KEY-----\n") user = Duse::User.find 'server' expect(user.username).to eq 'server' expect(user.email).to eq 'server@localhost' - expect(user.public_key.to_s).to eq public_key + expect(user.public_key.to_s).to eq public_key.to_s end end context 'any user' do it 'creates the correct entity when requesting a specific user' do stub_get_other_user - public_key = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Y1b9awjW0nshQXk64uO\n1v+GYliBH8ogu6QjQDn0eoLIfcOibrotbhJuSS0G46yOhboOCZQWrwyqi4MYtTMB\nH3ITTmNkhzOkdRXLJGJXXv3OCYR0J+PdCXbrtfYkvqOgyJE4RAR6YBEO/XcQk0Em\nE4IDFq22Aar7MxSjrLk17LX9mTifdzg1xdxX5myX4NrXGVWTWKeS5klLWCe9AigQ\n35b8c2Zyehx6jxHk+jt5CguMC9VqSyJobKdu926W4k2AgzWRdZh0EvCg2wWjlYjc\nhJEnrpHLeJxGMEThPoGqgQWiG5BBYIl9kx1vg1QZmS2biS6djGpGIn8l8PN30+QS\n5QIDAQAB\n-----END PUBLIC KEY-----\n" + public_key = OpenSSL::PKey::RSA.new("-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Y1b9awjW0nshQXk64uO\n1v+GYliBH8ogu6QjQDn0eoLIfcOibrotbhJuSS0G46yOhboOCZQWrwyqi4MYtTMB\nH3ITTmNkhzOkdRXLJGJXXv3OCYR0J+PdCXbrtfYkvqOgyJE4RAR6YBEO/XcQk0Em\nE4IDFq22Aar7MxSjrLk17LX9mTifdzg1xdxX5myX4NrXGVWTWKeS5klLWCe9AigQ\n35b8c2Zyehx6jxHk+jt5CguMC9VqSyJobKdu926W4k2AgzWRdZh0EvCg2wWjlYjc\nhJEnrpHLeJxGMEThPoGqgQWiG5BBYIl9kx1vg1QZmS2biS6djGpGIn8l8PN30+QS\n5QIDAQAB\n-----END PUBLIC KEY-----\n") user = Duse::User.find 3 expect(user.username).to eq 'adracus' expect(user.email).to eq 'adracus@example.org' - expect(user.public_key.to_s).to eq public_key + expect(user.public_key.to_s).to eq public_key.to_s end end end @@ -100,6 +100,6 @@ def stub_create_user expect(user.attributes['public_key']).to be nil expect(user.username).to eq 'adracus' expect(user.email).to eq 'adracus@example.org' - expect(user.public_key.to_s).to eq "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Y1b9awjW0nshQXk64uO\n1v+GYliBH8ogu6QjQDn0eoLIfcOibrotbhJuSS0G46yOhboOCZQWrwyqi4MYtTMB\nH3ITTmNkhzOkdRXLJGJXXv3OCYR0J+PdCXbrtfYkvqOgyJE4RAR6YBEO/XcQk0Em\nE4IDFq22Aar7MxSjrLk17LX9mTifdzg1xdxX5myX4NrXGVWTWKeS5klLWCe9AigQ\n35b8c2Zyehx6jxHk+jt5CguMC9VqSyJobKdu926W4k2AgzWRdZh0EvCg2wWjlYjc\nhJEnrpHLeJxGMEThPoGqgQWiG5BBYIl9kx1vg1QZmS2biS6djGpGIn8l8PN30+QS\n5QIDAQAB\n-----END PUBLIC KEY-----\n" + expect(user.public_key.to_s).to eq OpenSSL::PKey::RSA.new("-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Y1b9awjW0nshQXk64uO\n1v+GYliBH8ogu6QjQDn0eoLIfcOibrotbhJuSS0G46yOhboOCZQWrwyqi4MYtTMB\nH3ITTmNkhzOkdRXLJGJXXv3OCYR0J+PdCXbrtfYkvqOgyJE4RAR6YBEO/XcQk0Em\nE4IDFq22Aar7MxSjrLk17LX9mTifdzg1xdxX5myX4NrXGVWTWKeS5klLWCe9AigQ\n35b8c2Zyehx6jxHk+jt5CguMC9VqSyJobKdu926W4k2AgzWRdZh0EvCg2wWjlYjc\nhJEnrpHLeJxGMEThPoGqgQWiG5BBYIl9kx1vg1QZmS2biS6djGpGIn8l8PN30+QS\n5QIDAQAB\n-----END PUBLIC KEY-----\n").to_s end end From e494234a5db80fd3482b604a506ee14a6c1ededc Mon Sep 17 00:00:00 2001 From: flower-pot Date: Mon, 15 Jun 2015 19:24:29 +0200 Subject: [PATCH 6/9] fix formatting error in jruby and highline --- lib/duse/cli/share_with_user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/duse/cli/share_with_user.rb b/lib/duse/cli/share_with_user.rb index 9852a34..661a97f 100644 --- a/lib/duse/cli/share_with_user.rb +++ b/lib/duse/cli/share_with_user.rb @@ -32,7 +32,7 @@ def select_users(ignored_users = []) def select_from_list(subjects, method = :to_s) print_list(subjects, method) - selection = terminal.ask 'Type the ids of the users you want to share with (separate with commas to select multiple)' + selection = terminal.ask "Type the ids of the users you want to share with (separate with commas to select multiple)\n" CommaSeparatedIntegerList.new(selection).map do |i| fail InvalidSelection if subjects[i-1].nil? subjects[i-1] From b9c81fe0a6f476f78e8c21b85673ba9c60828d77 Mon Sep 17 00:00:00 2001 From: flower-pot Date: Mon, 15 Jun 2015 20:37:06 +0200 Subject: [PATCH 7/9] allow stdin to be part of stdout this somehow happens when using jruby --- spec/cli/commands/secret_spec.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/spec/cli/commands/secret_spec.rb b/spec/cli/commands/secret_spec.rb index 3f3b918..07098b2 100644 --- a/spec/cli/commands/secret_spec.rb +++ b/spec/cli/commands/secret_spec.rb @@ -66,8 +66,8 @@ run_cli('secret', 'get') { |i| i.puts('1') } - expect(last_run.out).to eq( - "1: test\n\nSelect the id of the secret to retrieve: \nName: test\nSecret: test\nAccess: flower-pot\n" + expect(last_run.out).to match( + "1: test\n\nSelect the id of the secret to retrieve: (1\n)?\nName: test\nSecret: test\nAccess: flower-pot\n" ) expect(last_run.err).to be_empty end @@ -125,13 +125,8 @@ i.puts '1' end.success?).to be true - expect(last_run.out).to eq( - "What do you want to call this secret? " + # new lines are in stdin not stdout - "Secret to save: " + - "Do you want to share this secret?[y/n] " + - "Who do you want to share this secret with?\n" + - "1: adracus\n" + - "Type the ids of the users you want to share with (separate with commas to select multiple)\n" + expect(last_run.out).to match( + /What do you want to call this secret\? (test\n)?Secret to save: (test\n)?Do you want to share this secret\?\[y\/n\] (y\n)?Who do you want to share this secret with\?\n1: adracus\nType the ids of the users you want to share with \(separate with commas to select multiple\)\n(1\n)?/ ) end end From b3c08ef619fd8be72a23255349ea38da678a566f Mon Sep 17 00:00:00 2001 From: flower-pot Date: Mon, 15 Jun 2015 21:10:58 +0200 Subject: [PATCH 8/9] add missing method --- lib/duse/cli/command.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/duse/cli/command.rb b/lib/duse/cli/command.rb index 25cf255..4291ece 100644 --- a/lib/duse/cli/command.rb +++ b/lib/duse/cli/command.rb @@ -217,6 +217,14 @@ def wrong_args(quantity) say help end end + + def format(data, format = nil, style = nil) + style ||= :important + data = format % color(data, style) if format and interactive? + data = data.gsub(/<\[\[/, '<%=').gsub(/\]\]>/, '%>') + data.encode! 'utf-8' if data.respond_to? :encode! + data + end end end end From a04667820e874a03c5f8757d2b35444e72db2ac8 Mon Sep 17 00:00:00 2001 From: flower-pot Date: Mon, 15 Jun 2015 22:26:14 +0200 Subject: [PATCH 9/9] remove debug opts might cause coverage reports to be incorrect, but it also causes exceptions to be printed to stdout which can cause tests to fail --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ad6b941..25da036 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,6 @@ matrix: jdk: oraclejdk7 - rvm: 2.2.2 jdk: oraclejdk8 -env: - - JRUBY_OPTS="-Xcli.debug=true --debug" sudo: false cache: bundler deploy: