From dccd924056a44f1093e6276d5450a17c569f9d27 Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Tue, 30 Apr 2024 10:49:51 +0200 Subject: [PATCH 01/10] Create GitHub actions to run tests --- .github/workflows/ruby.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/ruby.yml diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 0000000..900ef29 --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,37 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake +# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby + +name: Ruby + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + test: + + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: ['2.6', '2.7', '3.0'] + + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, + # change this to (see https://github.com/ruby/setup-ruby#versioning): + uses: ruby/setup-ruby@v1 # v1.146.0 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Run tests + run: bundle exec rake From dee5fcc2888ff1fb395800a252380c4165626af1 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Tue, 30 Apr 2024 11:56:37 +0200 Subject: [PATCH 02/10] Remove superfluous and unmaintained gem --- lib/threema/blob.rb | 1 - lib/threema/capabilities.rb | 2 -- lib/threema/lookup.rb | 6 ++---- lib/threema/receive.rb | 3 +-- lib/threema/send.rb | 1 - threema.gemspec | 1 - 6 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/threema/blob.rb b/lib/threema/blob.rb index 5d98281..b3bd3cc 100644 --- a/lib/threema/blob.rb +++ b/lib/threema/blob.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'case_transform' require 'threema/exceptions' class Threema diff --git a/lib/threema/capabilities.rb b/lib/threema/capabilities.rb index c5b1305..e12d486 100644 --- a/lib/threema/capabilities.rb +++ b/lib/threema/capabilities.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'case_transform' - class Threema class Capabilities class << self diff --git a/lib/threema/lookup.rb b/lib/threema/lookup.rb index 956a0e4..9baab6e 100644 --- a/lib/threema/lookup.rb +++ b/lib/threema/lookup.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'case_transform' - class Threema class Lookup URL_PATH = { @@ -67,7 +65,7 @@ def bulk(params) def keys_camel_lower(params) cameled = {} params.each do |key, value| - cameled[CaseTransform.camel_lower(key.to_s)] = value + cameled[key.to_s.camelize(:lower)] = value end cameled end @@ -76,7 +74,7 @@ def underscore_entry_keys(list) list.collect do |response_entry| result_entry = {} response_entry.each do |key, value| - result_entry[CaseTransform.underscore(key).to_sym] = value + result_entry[key.underscore.to_sym] = value end result_entry diff --git a/lib/threema/receive.rb b/lib/threema/receive.rb index 2d1e874..4cca456 100644 --- a/lib/threema/receive.rb +++ b/lib/threema/receive.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'case_transform' require 'threema/e2e/mac' require 'threema/typed_message' require 'threema/lookup' @@ -65,7 +64,7 @@ def classify(type) end def class_name(type) - class_name = CaseTransform.camel(type.to_s) + class_name = type.to_s.camelize "Threema::Receive::#{class_name}" end diff --git a/lib/threema/send.rb b/lib/threema/send.rb index 19f876f..954632f 100644 --- a/lib/threema/send.rb +++ b/lib/threema/send.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'case_transform' require 'threema/exceptions' require 'threema/send/simple' require 'threema/send/text' diff --git a/threema.gemspec b/threema.gemspec index 38ff347..c166bcf 100644 --- a/threema.gemspec +++ b/threema.gemspec @@ -21,7 +21,6 @@ Gem::Specification.new do |spec| spec.files = Dir['{lib}/**/*'] spec.require_paths = ['lib'] - spec.add_runtime_dependency 'case_transform' spec.add_runtime_dependency 'dotenv' spec.add_runtime_dependency 'mimemagic' spec.add_runtime_dependency 'mime-types' From 9721083e6384b845e7f227853eb2e05fc8ffe89a Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Tue, 30 Apr 2024 12:08:20 +0200 Subject: [PATCH 03/10] Fix broken tests - Flaky since they rely on the sha256 fingerprint, which changes over time --- spec/threema/client_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/threema/client_spec.rb b/spec/threema/client_spec.rb index 0a7d4d0..a0ac00a 100644 --- a/spec/threema/client_spec.rb +++ b/spec/threema/client_spec.rb @@ -53,8 +53,8 @@ before(:each) do instance.configure do |config| - # Threema API fingerprint as of 2021-02-27 - fingerprint = '42b1038e72f00c8c4dad78a3ebdc6d7a50c5ef288da9019b9171e4d675c08a17' + # Threema API fingerprint as of 2024-04-30 + fingerprint = '317bc8626c34a2ccd9052164828f4eb71a6bc6290e2569acee5b3a2cbde13d2a' # See: http://stackoverflow.com/a/22108461 config.use_ssl = true @@ -87,7 +87,7 @@ end context 'given another URL without matching certificate' do - let(:url) { 'https://github.com/thorsteneckel/threema' } + let(:url) { 'https://github.com/threemarb/threema' } it { should raise_error(OpenSSL::SSL::SSLError) } context 'but if static certificate pinning is disabled' do From fc4dc44e658ac9d7ddedda26d8bd3e46e931e1cd Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Tue, 30 Apr 2024 12:09:01 +0200 Subject: [PATCH 04/10] Remove travis config --- .travis.yml | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b6e28c4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -sudo: false -language: ruby -rvm: - - 2.6.6 - - 2.7.2 - - 3.0.0 -before_install: - - sudo apt-get update - - sudo apt-get install -y libsodium-dev - - gem update --system - - gem --version - - gem install bundler From 4e620e119acff2a55ea90cd757fcae79d540c621 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Tue, 30 Apr 2024 12:43:17 +0200 Subject: [PATCH 05/10] Add activesupport as runtime dependency it is required to run commands such as `.blank?`. Previously it was being installed upstream in the deprecated case_transform gem --- threema.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/threema.gemspec b/threema.gemspec index c166bcf..08a888c 100644 --- a/threema.gemspec +++ b/threema.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |spec| spec.files = Dir['{lib}/**/*'] spec.require_paths = ['lib'] + spec.add_runtime_dependency 'activesupport', '~> 7.0.8' spec.add_runtime_dependency 'dotenv' spec.add_runtime_dependency 'mimemagic' spec.add_runtime_dependency 'mime-types' From ce2cd04670387d7368100a3fd26b37a8837ac17f Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Tue, 30 Apr 2024 13:11:25 +0200 Subject: [PATCH 06/10] Start to add hardcoded mock values - tests still failing locally... --- spec/support/shared_values.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/support/shared_values.rb b/spec/support/shared_values.rb index dc6b355..22847cf 100644 --- a/spec/support/shared_values.rb +++ b/spec/support/shared_values.rb @@ -9,11 +9,11 @@ def hello_world end def test_public_key - ENV['THREEMARB_PUBLIC'] + '2edf856e8a0f8f8e761be57f895f8827f42c6be0c6c891b95494faa7d264f7d9' end def test_private_key - ENV['THREEMARB_PRIVATE'] + '2edf856e8a0f8f8e761be57f895f8827f42c6be0c6c891b95494faa7d264f7d9' end def test_auth_params @@ -24,11 +24,11 @@ def test_auth_params end def test_from - ENV['THREEMARB_API_IDENTITY'] + '*VALID1' end def test_api_secret - ENV['THREEMARB_API_SECRET'] + 'CWWuNaFDkEZLiRSt' end def test_blob_id From b7aba27ce7840016ead6a6a1a59f120613d25764 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Fri, 3 May 2024 07:48:03 +0200 Subject: [PATCH 07/10] Fix failing tests --- .github/workflows/ruby.yml | 2 +- lib/threema/client.rb | 1 + spec/factories/threema.rb | 1 + spec/factories/threema_client.rb | 2 +- spec/support/shared_values.rb | 2 +- spec/threema/client_spec.rb | 30 +++++++++++++----------------- threema.gemspec | 2 +- 7 files changed, 19 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 900ef29..1131471 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.6', '2.7', '3.0'] + ruby-version: ['2.7', '3.0'] steps: - uses: actions/checkout@v4 diff --git a/lib/threema/client.rb b/lib/threema/client.rb index 43caecb..7596362 100644 --- a/lib/threema/client.rb +++ b/lib/threema/client.rb @@ -35,6 +35,7 @@ def configure(&block) def get(url, params = {}) response = handle_error do uri = authed_uri(url, params) + # binding.pry req = Net::HTTP::Get.new(uri) request_https(uri, req) diff --git a/spec/factories/threema.rb b/spec/factories/threema.rb index 7535db8..9c9e2ce 100644 --- a/spec/factories/threema.rb +++ b/spec/factories/threema.rb @@ -4,6 +4,7 @@ factory :threema do api_identity { test_from } api_secret { test_api_secret } + private_key { test_private_key } initialize_with do new(**attributes) diff --git a/spec/factories/threema_client.rb b/spec/factories/threema_client.rb index ff24ee7..d572fc4 100644 --- a/spec/factories/threema_client.rb +++ b/spec/factories/threema_client.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :threema_client, class: Threema::Client do - threema { FactoryBot.build(:threema) } + threema initialize_with do new(**attributes) diff --git a/spec/support/shared_values.rb b/spec/support/shared_values.rb index 22847cf..61af51b 100644 --- a/spec/support/shared_values.rb +++ b/spec/support/shared_values.rb @@ -9,7 +9,7 @@ def hello_world end def test_public_key - '2edf856e8a0f8f8e761be57f895f8827f42c6be0c6c891b95494faa7d264f7d9' + 'd981f35570026a9551fbb27709087fe9c268b8f1395998b4ae5019476cd58fae' end def test_private_key diff --git a/spec/threema/client_spec.rb b/spec/threema/client_spec.rb index a0ac00a..e7308c9 100644 --- a/spec/threema/client_spec.rb +++ b/spec/threema/client_spec.rb @@ -11,8 +11,8 @@ expect(described_class).to respond_to(:url) end - let(:instance) { build(:threema_client, threema: threema) } - let(:threema) { build(:threema) } + let(:instance) { build(:threema_client) } + let!(:threema) { build(:threema) } context '#not_found_ok' do it 'responds to not_found_ok' do @@ -43,13 +43,13 @@ context 'with static certificate pinning' do let(:public_key_pinning) { true } - before(:all) do - WebMock.allow_net_connect! - end + # before(:all) do + # WebMock.allow_net_connect! + # end - after(:all) do - WebMock.disable_net_connect! - end + # after(:all) do + # WebMock.disable_net_connect! + # end before(:each) do instance.configure do |config| @@ -74,15 +74,11 @@ end end - # this is needed due to internet access restrictions - # in the (travis) CI environment - if !ENV['CI'] - context 'given Threema Message API URL with matching certificate' do - let(:url) { described_class::API_URL } - it 'checks HTTP Public Key Pinning' do - should raise_error(RequestError) - # not OpenSSL::SSL::SSLError - end + context 'given Threema Message API URL with matching certificate' do + let(:url) { described_class::API_URL } + it 'checks HTTP Public Key Pinning' do + should raise_error(RequestError) + # not OpenSSL::SSL::SSLError end end diff --git a/threema.gemspec b/threema.gemspec index 08a888c..376a73d 100644 --- a/threema.gemspec +++ b/threema.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |spec| spec.homepage = 'https://github.com/thorsteneckel/threema' spec.license = 'MIT' - spec.required_ruby_version = '>= 2.6.0' + spec.required_ruby_version = '>= 2.7.0' spec.files = Dir['{lib}/**/*'] spec.require_paths = ['lib'] From 5a3b3da2fe136177a3185abd769fe0128dda6f52 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Fri, 3 May 2024 07:50:02 +0200 Subject: [PATCH 08/10] Continue skipping singular test in CI --- spec/threema/client_spec.rb | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/spec/threema/client_spec.rb b/spec/threema/client_spec.rb index e7308c9..0e65d0c 100644 --- a/spec/threema/client_spec.rb +++ b/spec/threema/client_spec.rb @@ -43,13 +43,13 @@ context 'with static certificate pinning' do let(:public_key_pinning) { true } - # before(:all) do - # WebMock.allow_net_connect! - # end + before(:all) do + WebMock.allow_net_connect! + end - # after(:all) do - # WebMock.disable_net_connect! - # end + after(:all) do + WebMock.disable_net_connect! + end before(:each) do instance.configure do |config| @@ -74,11 +74,15 @@ end end - context 'given Threema Message API URL with matching certificate' do - let(:url) { described_class::API_URL } - it 'checks HTTP Public Key Pinning' do - should raise_error(RequestError) - # not OpenSSL::SSL::SSLError + # skipped in CI because this test requires actual + # private key, identity, etc set in .env variables + if !ENV['CI'] + context 'given Threema Message API URL with matching certificate' do + let(:url) { described_class::API_URL } + it 'checks HTTP Public Key Pinning' do + should raise_error(RequestError) + # not OpenSSL::SSL::SSLError + end end end From 1fa278c03e3ddfa5f7bc0c26f0e7569191e5d879 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Fri, 3 May 2024 08:10:54 +0200 Subject: [PATCH 09/10] Remove codecov and code-climate-test-reporter codecov is no longer configured, is not free, and is currently blocking running tests in CI --- README.md | 6 ------ spec/spec_helper.rb | 8 +------- threema.gemspec | 2 -- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/README.md b/README.md index a081da0..83d8c0f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,5 @@ # threema -[![Build Status](https://travis-ci.org/thorsteneckel/threema.svg?branch=master)](https://travis-ci.org/thorsteneckel/threema) -[![codecov](https://codecov.io/gh/thorsteneckel/threema/branch/master/graph/badge.svg)](https://codecov.io/gh/thorsteneckel/threema) -[![Code Climate](https://codeclimate.com/github/thorsteneckel/threema/badges/gpa.svg)](https://codeclimate.com/github/thorsteneckel/threema) -[![Gem](https://img.shields.io/gem/v/threema.svg?maxAge=2592000)]() - - This gem provides access to the Threema Gateway API. ## Installation diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 055d526..347d6b1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,19 +10,13 @@ require 'pry' require 'simplecov' -require 'codecov' -require 'codeclimate-test-reporter' SimpleCov.start do # Don't get coverage on the test cases themselves. add_filter '/spec/' add_filter '/test/' - # Codecov doesn't automatically ignore vendored files. - add_filter '/vendor/' end -SimpleCov.formatter = SimpleCov::Formatter::Codecov - -CodeClimate::TestReporter.start +SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter require 'threema' diff --git a/threema.gemspec b/threema.gemspec index 376a73d..9f38b4b 100644 --- a/threema.gemspec +++ b/threema.gemspec @@ -29,8 +29,6 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'rbnacl' spec.add_development_dependency 'bundler' - spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.6' - spec.add_development_dependency 'codecov' spec.add_development_dependency 'factory_bot' spec.add_development_dependency 'fakefs' spec.add_development_dependency 'pry' From 9be1909d91efb6f6ed89020bd3bd9c7664275bb8 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Fri, 3 May 2024 08:20:53 +0200 Subject: [PATCH 10/10] Remove commented out pry statement --- lib/threema/client.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/threema/client.rb b/lib/threema/client.rb index 7596362..43caecb 100644 --- a/lib/threema/client.rb +++ b/lib/threema/client.rb @@ -35,7 +35,6 @@ def configure(&block) def get(url, params = {}) response = handle_error do uri = authed_uri(url, params) - # binding.pry req = Net::HTTP::Get.new(uri) request_https(uri, req)