From 4b573e4b397609d74acace6b7d8a8954dc4707a4 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 13 Oct 2021 12:00:33 +0300 Subject: [PATCH 1/5] made changes in build_deploy_staging --- .github/workflows/build_deploy_staging.yml | 1 + .gitignore | 2 +- config/application.yml.sample | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_deploy_staging.yml b/.github/workflows/build_deploy_staging.yml index e8147bb1..40e7a520 100644 --- a/.github/workflows/build_deploy_staging.yml +++ b/.github/workflows/build_deploy_staging.yml @@ -48,6 +48,7 @@ jobs: cp config/database.yml.sample config/database.yml cp config/application.yml.sample config/application.yml sed -i -e 's/BASE_URL: "http:\/\/registry:3000"/BASE_URL: "https:\/\/reg-api-accreditation-'$PR_REF'.pilv.tld.ee"/' config/application.yml + sed -i -e 's/BASE_REPP_URL: "http:\/\/registry:3000"/BASE_REPP_URL: "https:\/\/repp-accreditation-'$PR_REF'.pilv.tld.ee"/' config/application.yml ls -l config/ - name: Build rails image diff --git a/.gitignore b/.gitignore index 9b80004f..6ab70a94 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ # Ignore bundler config. /.bundle - +.idea # Ignore the default SQLite database. /db/*.sqlite3 /db/*.sqlite3-* diff --git a/config/application.yml.sample b/config/application.yml.sample index 89870990..3cb3aad9 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -3,8 +3,7 @@ # Temporary secret key for registry TEMPORARY_SECRET_KEY: "temporary-secret-key" BASE_URL: "http://registry:3000" -REPP_STAGING_BASE_URL: "https://st-repp.infra.tld.ee" -API_STAGING_BASE_URL: "https://st-api.infra.tld.ee" +BASE_REPP_URL: "http://registry:3000" GET_INFO: "/api/v1/accreditation_center/auth" From 884744aeee487198f229e568d48bee4c360f12dc Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 13 Oct 2021 12:01:05 +0300 Subject: [PATCH 2/5] changed endpoint for create domain to repp endpoint --- app/services/create_domain.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/create_domain.rb b/app/services/create_domain.rb index 7c07ddfb..1ef808c2 100644 --- a/app/services/create_domain.rb +++ b/app/services/create_domain.rb @@ -5,7 +5,7 @@ def initialize(username:, password:) end def domain_endpoint - base_url = ENV['BASE_URL'] + base_url = ENV['BASE_REPP_URL'] endpoint = ENV['CREATE_DOMAIN'] base_url + endpoint From a91fa96a765c3188efe4d0009785154f83b54c05 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 13 Oct 2021 12:03:27 +0300 Subject: [PATCH 3/5] changed test --- spec/services/create_domain_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/create_domain_spec.rb b/spec/services/create_domain_spec.rb index e5cc3ffc..42162681 100644 --- a/spec/services/create_domain_spec.rb +++ b/spec/services/create_domain_spec.rb @@ -55,7 +55,7 @@ end it "should return endpoint" do - ENV['BASE_URL'] = 'https://api.website' + ENV['BASE_REPP_URL'] = 'https://api.website' ENV['CREATE_DOMAIN'] = '/repp/domains/' api_connector = CreateDomain.new(username: user.username, password: user.password) From d0d1869d3c401cc9a43c72bd675909ed84d02455 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 13 Oct 2021 13:20:04 +0300 Subject: [PATCH 4/5] added keys in application.yml.sample and added ssl parameter to faraday request --- app/services/api_connector.rb | 8 ++++---- app/services/create_domain.rb | 11 ++++++++++- config/application.yml.sample | 4 ++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/services/api_connector.rb b/app/services/api_connector.rb index 494c2630..df58b275 100644 --- a/app/services/api_connector.rb +++ b/app/services/api_connector.rb @@ -9,8 +9,8 @@ def initialize(username:, password:) private - def request(url:, method:, headers:, params: nil) - request = faraday_request(url: url, headers: headers, params: params) + def request(url:, method:, headers:, params: nil, ssl: nil) + request = faraday_request(url: url, headers: headers, params: params, ssl: ssl) response = request.send(method) JSON.parse(response.body) end @@ -19,12 +19,12 @@ def generate_token(username:, password:) Base64.urlsafe_encode64("#{username}:#{password}") end - def faraday_request(url:, headers:, params: {}) + def faraday_request(url:, headers:, params: {}, ssl:) Faraday.new( url: url, headers: headers, params: params, - ssl: { verify: false} + ssl: ssl ) end end diff --git a/app/services/create_domain.rb b/app/services/create_domain.rb index 1ef808c2..9aee5f0e 100644 --- a/app/services/create_domain.rb +++ b/app/services/create_domain.rb @@ -1,4 +1,13 @@ +require 'openssl' +require 'net/http' +require 'json' + class CreateDomain < ApiConnector + SSL_OPTIONS = { + client_cert: OpenSSL::X509::Certificate.new(File.read(ENV['CLIENT_CERTS_PATH'])), + client_key: OpenSSL::PKey::RSA.new(File.read(ENV['CLIENT_KEY_PATH']), ENV['CLIENT_PASSWORD']) + }.freeze + def initialize(username:, password:) super @@ -17,7 +26,7 @@ def headers end def create_domain - request(url: domain_endpoint, headers: headers, method: :post, params: payload) + request(url: domain_endpoint, headers: headers, method: :post, params: payload, ssl: SSL_OPTIONS) end private diff --git a/config/application.yml.sample b/config/application.yml.sample index 3cb3aad9..dd0ac81a 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -21,3 +21,7 @@ ACCR_USERNAME: "accr_bot" ACCR_PASSWORD: "123456" ACCR_CONTACT_CODE: "1234566:8A125009" ACCR_REGISTRAR_NAME: "ACCREDITATION EIS" + +CLIENT_CERTS_PATH: '/opt/ca/certs/accr_bot.crt.pem' +CLIENT_KEY_PATH: '/opt/ca/private/client.key' +CLIENT_PASSWORD: '123456' From 8c5a1a41cbd28c787deb2c6a8880eec988e98ab2 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 13 Oct 2021 13:28:28 +0300 Subject: [PATCH 5/5] tests refactored --- app/services/create_domain.rb | 12 ++++++++---- spec/services/api_connector_spec.rb | 2 +- spec/services/create_domain_spec.rb | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/services/create_domain.rb b/app/services/create_domain.rb index 9aee5f0e..32936dba 100644 --- a/app/services/create_domain.rb +++ b/app/services/create_domain.rb @@ -3,10 +3,14 @@ require 'json' class CreateDomain < ApiConnector - SSL_OPTIONS = { - client_cert: OpenSSL::X509::Certificate.new(File.read(ENV['CLIENT_CERTS_PATH'])), - client_key: OpenSSL::PKey::RSA.new(File.read(ENV['CLIENT_KEY_PATH']), ENV['CLIENT_PASSWORD']) - }.freeze + if Rails.env.test? + SSL_OPTIONS = nil.freeze + else + SSL_OPTIONS = { + client_cert: OpenSSL::X509::Certificate.new(File.read(ENV['CLIENT_CERTS_PATH'])), + client_key: OpenSSL::PKey::RSA.new(File.read(ENV['CLIENT_KEY_PATH']), ENV['CLIENT_PASSWORD']) + }.freeze + end def initialize(username:, password:) super diff --git a/spec/services/api_connector_spec.rb b/spec/services/api_connector_spec.rb index 4ea6cd4f..fd552158 100644 --- a/spec/services/api_connector_spec.rb +++ b/spec/services/api_connector_spec.rb @@ -11,7 +11,7 @@ allow(body).to receive(:body).and_return(response) api_connector = ApiConnector.new(username: "mock", password: "username") - allow(api_connector).to receive(:faraday_request).with(url: "https://something", headers: {}, params: {}).and_return(Faraday) + allow(api_connector).to receive(:faraday_request).with(url: "https://something", headers: {}, params: {}, ssl: nil).and_return(Faraday) allow(Faraday).to receive(:send).with(:get).and_return(body) diff --git a/spec/services/create_domain_spec.rb b/spec/services/create_domain_spec.rb index 42162681..0d03d90f 100644 --- a/spec/services/create_domain_spec.rb +++ b/spec/services/create_domain_spec.rb @@ -39,7 +39,8 @@ allow(@api_connector).to receive(:request).with(url: @api_connector.domain_endpoint, headers: @api_connector.headers, method: :post, - params: payload).and_return(@response_successful) + params: payload, + ssl: nil).and_return(@response_successful) response = @api_connector.create_domain expect(response["code"]).to eq("1000")