Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Remove restdt 2fa strategy

Oliver Günther9b14678e638f
diff --git a/modules/two_factor_authentication/config/locales/en.yml b/modules/two_factor_authentication/config/locales/en.yml
index e8109e9057f..3ff2ce132d1 100644
--- a/modules/two_factor_authentication/config/locales/en.yml
+++ b/modules/two_factor_authentication/config/locales/en.yml
@@ -138,8 +138,6 @@ en:
message_bird:
sms_delivery_failed: 'MessageBird SMS delivery failed.'
voice_delivery_failed: 'MessageBird voice call failed.'
- restdt:
- delivery_failed_with_code: 'Token delivery failed. (Error code %{code})'
strategies:
totp: 'Authenticator application'
diff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/restdt.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/restdt.rb
deleted file mode 100644
index 629be93d7b0..00000000000
--- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/restdt.rb
+++ /dev/null
@@ -1,112 +0,0 @@
-require 'net/http'
-
-module OpenProject::TwoFactorAuthentication
- module TokenStrategy
- class Restdt < Base
- def self.validate!
- if configuration_params.nil?
- raise ArgumentError, 'Missing configuration hash'
- end
-
- validate_params configuration_params
- end
-
- def self.identifier
- :restdt
- end
-
- def self.mobile_token?
- true
- end
-
- def self.supported_channels
- %i[sms voice]
- end
-
- private
-
- def service_params
- {
- url: URI(configuration_params['service_url']),
- request_base: {
- user: configuration_params['username'],
- pass: configuration_params['password'],
- # The API supports XML and plain.
- # In the latter case, only the status code is returned.
- output: 'plain'
- }
- }
- end
-
- def send_sms
- Rails.logger.info { "[2FA] REST DT delivery sending SMS request for #{user.login}" }
- submit(build_user_params(onlycall: '0'))
- end
-
- def send_voice
- Rails.logger.info { "[2FA] REST DT delivery sending VOICE request for #{user.login}" }
- submit(build_user_params(onlycall: '1'))
- end
-
- def service_url
- service_params[:url]
- end
-
- ##
- # Prepares the request for the given user and token
- def build_user_params(merge_params)
- language = user.language == 'de' ? 'de' : 'en'
-
- merge_params[:lang] = language
- merge_params[:rec] = build_user_phone
- merge_params[:txt] = token
- service_params[:request_base].merge(merge_params)
- end
-
- ##
- # Prepares the user's phone number for commcit.
- # Required format: 0152xxxxxxx or 0049xxxxxxxxx
- # Stored format: +xx yyy yyy yyyy (optional whitespacing)
- def build_user_phone
- phone = device.phone_number
- phone.gsub!(/\+/, '00')
- phone.gsub!(/\s/, '')
-
- phone
- end
-
- def submit(params)
- http = Net::HTTP.new(service_url.host, service_url.port)
- http.use_ssl = true
-
- request = Net::HTTP::Post.new(service_url.request_uri)
- request.set_form_data(params)
- response = http.request(request)
-
- # What a stupid API is this to return the code in their body
- # instead of the actual response code?
- code = response.body.strip
-
- if code == '200'
- Rails.logger.info { "[2FA] REST DT delivery succeeded for user #{user.login}" }
- return
- end
-
- Rails.logger.error do
- "[2FA] REST DT delivery failed for user #{user.login} " \
- "(Error #{response.body})"
- end
-
- raise I18n.t('two_factor_authentication.restdt.delivery_failed_with_code', code:)
- end
-
- def self.validate_params(params)
- %i(username password service_url).each do |key|
- unless params[key]
- raise ArgumentError, "REST DT delivery settings is missing mandatory key :#{key}"
- end
- end
- end
- end
- end
-end
diff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy_manager.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy_manager.rb
index e910bd9067b..1a00c114524 100644
--- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy_manager.rb
+++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy_manager.rb
@@ -125,7 +125,6 @@ module OpenProject::TwoFactorAuthentication
{
totp: I18n.t("activerecord.models.two_factor_authentication/device/totp"),
sns: I18n.t("activerecord.models.two_factor_authentication/device/sms"),
- restdt: I18n.t("activerecord.models.two_factor_authentication/device/restdt"),
message_bird: I18n.t("activerecord.models.two_factor_authentication/device/sms")
}
end
diff --git a/modules/two_factor_authentication/spec/services/token_delivery/restdt_spec.rb b/modules/two_factor_authentication/spec/services/token_delivery/restdt_spec.rb
deleted file mode 100644
index 1305065e280..00000000000
--- a/modules/two_factor_authentication/spec/services/token_delivery/restdt_spec.rb
+++ /dev/null
@@ -1,115 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
-
-describe ::OpenProject::TwoFactorAuthentication::TokenStrategy::Restdt, with_2fa_ee: true do
- describe 'sending messages' do
- let!(:user) { create :user }
- let!(:device) { create :two_factor_authentication_device_sms, user:, channel: }
-
- let(:service_url) { 'https://example.org/foobar' }
- let(:params) do
- {
- service_url:,
- username: 'foobar',
- password: 'password!'
- }
- end
-
- let(:base_request) do
- {
- user: 'foobar',
- pass: 'password!',
- rec: '0049123456789',
- lang: 'en',
- txt: '1234',
- output: 'plain'
- }
- end
-
- let(:result) { subject.request }
-
- subject { ::TwoFactorAuthentication::TokenService.new user: }
-
- include_context 'with settings' do
- let(:settings) do
- {
- plugin_openproject_two_factor_authentication: {
- 'active_strategies' => [:restdt],
- 'restdt' => params
- }
- }
- end
- end
-
- before do
- allow_any_instance_of(::OpenProject::TwoFactorAuthentication::TokenStrategy::Restdt)
- .to receive(:create_mobile_otp)
- .and_return('1234')
- end
-
- describe '#setup' do
- let(:channel) { :sms }
- let(:params) { { service_url: nil } }
-
- it 'raises an exception for incomplete params' do
- expect { described_class.validate! }
- .to raise_exception(ArgumentError)
- end
- end
-
- describe 'calling a mocked API', webmock: true do
- let(:response_code) { '200' }
- let(:channel) { :sms }
-
- before do
- stub_request(:post, service_url).to_return(status: 200, body: response_code)
- end
-
- shared_examples 'API response' do |success, errors|
- it 'calls the API' do
- expect(result.success).to eq success
-
- unless errors.nil?
- expect(result.errors.messages).to eq(base: errors)
- end
-
- expect(WebMock).to have_requested(:post, service_url).with { |request|
- requested_params = URI.decode_www_form(request.body).to_h.with_indifferent_access
- expect(requested_params).to include(base_request.merge(expected_params))
- }
- end
- end
-
- describe 'request body' do
- context 'with SMS' do
- let(:expected_params) { { onlycall: '0' } }
-
- it_behaves_like 'API response', true
- end
-
- context 'with voice' do
- let(:channel) { :voice }
- let(:expected_params) { { onlycall: '1' } }
-
- it_behaves_like 'API response', true
- end
-
- context 'with german locale' do
- let(:user) { create(:user, language: 'de') }
- let(:expected_params) { { lang: 'de' } }
-
- it_behaves_like 'API response', true
- end
- end
-
- context 'when error' do
- let(:response_code) { '400' }
- let(:channel) { :sms }
- let(:expected_params) { { onlycall: '0' } }
-
- it_behaves_like 'API response',
- false,
- [I18n.t('two_factor_authentication.restdt.delivery_failed_with_code', code: 400)]
- end
- end
- end
-end