From 4127bf77ce14848ef361c8838c89ebb9e8841a80 Mon Sep 17 00:00:00 2001 From: Semyon Estrin <89914704+semyon-estrin@users.noreply.github.com> Date: Thu, 9 Dec 2021 17:08:10 +0200 Subject: [PATCH] Support ruby 3.0.2 (#197) * Resolve compatability with ruby-3.0.2 --- CHANGELOG.md | 3 +++ Gemfile | 2 +- Jenkinsfile | 22 +++++++++++++++++++--- conjur-api.gemspec | 3 ++- lib/conjur/escape.rb | 5 ++--- spec/api_spec.rb | 11 ++++------- test.sh | 6 +++++- 7 files changed, 36 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 207c834f..188dba72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- Upgrade and set ruby-3.0.2 as default. + [cyberark/conjur-api-ruby#197](https://github.com/cyberark/conjur-api-ruby/pull/197) ## [5.3.5] - 2021-05-04 diff --git a/Gemfile b/Gemfile index a4b9c137..70020dba 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -#ruby=ruby-2.7 +#ruby=ruby-3.0 #ruby-gemset=conjur-api # Specify your gem's dependencies in conjur-api.gemspec diff --git a/Jenkinsfile b/Jenkinsfile index 914d93a2..66d65178 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,7 +26,7 @@ pipeline { } } - stage('Test 2.5') { + stage('Test Ruby 2.5') { environment { RUBY_VERSION = '2.5' } @@ -43,7 +43,7 @@ pipeline { } } - stage('Test 2.6') { + stage('Test Ruby 2.6') { environment { RUBY_VERSION = '2.6' } @@ -60,7 +60,7 @@ pipeline { } } - stage('Test 2.7') { + stage('Test Ruby 2.7') { environment { RUBY_VERSION = '2.7' } @@ -77,6 +77,22 @@ pipeline { } } + stage('Test Ruby 3.0') { + environment { + RUBY_VERSION = '3.0' + } + steps { + sh("./test.sh") + } + post { + always { + junit 'spec/reports/*.xml' + junit 'features/reports/*.xml' + junit 'features_v4/reports/*.xml' + } + } + } + stage('Submit Coverage Report'){ steps{ sh 'ci/submit-coverage' diff --git a/conjur-api.gemspec b/conjur-api.gemspec index acb16382..f8f448b4 100644 --- a/conjur-api.gemspec +++ b/conjur-api.gemspec @@ -22,7 +22,8 @@ Gem::Specification.new do |gem| gem.executables -= %w{parse-changelog.sh} gem.add_dependency 'rest-client' - gem.add_dependency 'activesupport' + gem.add_dependency 'activesupport', '>= 4.2' + gem.add_dependency 'addressable', '~> 2.8.0' gem.add_development_dependency 'rake', '>= 12.3.3' gem.add_development_dependency 'rspec', '~> 3' diff --git a/lib/conjur/escape.rb b/lib/conjur/escape.rb index 5243397b..fd45f6ad 100644 --- a/lib/conjur/escape.rb +++ b/lib/conjur/escape.rb @@ -80,9 +80,8 @@ def path_or_query_escape(str) return "false" unless str str = str.id if str.respond_to?(:id) # Leave colons and forward slashes alone - require 'uri' - pattern = URI::PATTERN::UNRESERVED + ":\\/@" - URI.escape(str.to_s, Regexp.new("[^#{pattern}]")) + require 'addressable/uri' + Addressable::URI.encode(str.to_s) end end diff --git a/spec/api_spec.rb b/spec/api_spec.rb index 9aca9ee2..7ab11152 100644 --- a/spec/api_spec.rb +++ b/spec/api_spec.rb @@ -4,29 +4,26 @@ describe Conjur::API do let(:account) { 'api-spec-acount' } + let(:remote_ip) { nil } before { allow(Conjur.configuration).to receive_messages account: account } shared_context "logged in", logged_in: true do let(:login) { "bob" } let(:token) { { 'data' => login, 'timestamp' => Time.now.to_s } } - let(:remote_ip) { nil } - let(:api_args) { [ token, { remote_ip: remote_ip } ] } - subject(:api) { Conjur::API.new_from_token(*api_args) } + subject(:api) { Conjur::API.new_from_token(token, remote_ip: remote_ip) } end shared_context "logged in with an API key", logged_in: :api_key do include_context "logged in" let(:api_key) { "theapikey" } - let(:api_args) { [ login, api_key, { remote_ip: remote_ip, account: account } ] } - subject(:api) { Conjur::API.new_from_key(*api_args) } + subject(:api) { Conjur::API.new_from_key(login, api_key, account: account ,remote_ip: remote_ip) } end shared_context "logged in with a token file", logged_in: :token_file do include FakeFS::SpecHelpers include_context "logged in" let(:token_file) { "token_file" } - let(:api_args) { [ token_file, { remote_ip: remote_ip } ] } - subject(:api) { Conjur::API.new_from_token_file(*api_args) } + subject(:api) { Conjur::API.new_from_token_file(token_file, remote_ip: remote_ip) } end def time_travel delta diff --git a/test.sh b/test.sh index bbd2f30d..7ade9146 100755 --- a/test.sh +++ b/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -e -: "${RUBY_VERSION=2.7}" +: "${RUBY_VERSION=3.0}" # My local RUBY_VERSION is set to ruby-#.#.# so this allows running locally. RUBY_VERSION="$(cut -d '-' -f 2 <<< "$RUBY_VERSION")" @@ -15,6 +15,10 @@ trap finish EXIT function main() { + if ! docker info >/dev/null 2>&1; then + echo "Docker does not seem to be running, run it first and retry" + exit 1 + fi # Generate reports folders locally mkdir -p spec/reports features/reports features_v4/reports