From 9f21145cee3acac8ee5878acd71d19d902a50f94 Mon Sep 17 00:00:00 2001 From: superchilled Date: Wed, 7 Aug 2024 11:23:18 +0100 Subject: [PATCH] Removing hashed option from network number verification --- lib/vonage/network_number_verification.rb | 11 +++---- .../network_number_verification_test.rb | 33 ------------------- 2 files changed, 4 insertions(+), 40 deletions(-) diff --git a/lib/vonage/network_number_verification.rb b/lib/vonage/network_number_verification.rb index 967894c1..f07b3e6a 100644 --- a/lib/vonage/network_number_verification.rb +++ b/lib/vonage/network_number_verification.rb @@ -31,23 +31,20 @@ class NetworkNumberVerification < Namespace # @option auth_data [required, String] :redirect_uri The redirect URI. # @see https://developer.vonage.com/en/getting-started-network/authentication#client-authentication-flow # - # @param [required, Boolean] :hashed Whether the value of `phone_number` is hashed (true) or not hashed (false, the default). - # # @return [Response] # # @see https://developer.vonage.com/en/api/camara/number-verification#verifyNumberVerification # - sig { params(phone_number: String, auth_data: Hash, hashed: T::Boolean).returns(Vonage::Response) } - def verify(phone_number:, auth_data:, hashed: false) - raise ArgumentError.new("`phone_number` must be in E.164 format") unless Phonelib.parse(phone_number).valid? || hashed == true - raise ArgumentError.new("`phone_number` must be prepended with a `+`") unless phone_number.start_with?('+') || hashed == true + sig { params(phone_number: String, auth_data: Hash).returns(Vonage::Response) } + def verify(phone_number:, auth_data:) + raise ArgumentError.new("`phone_number` must be in E.164 format") unless Phonelib.parse(phone_number).valid? + raise ArgumentError.new("`phone_number` must be prepended with a `+`") unless phone_number.start_with?('+') raise ArgumentError.new("`auth_data` must contain key `:oidc_auth_code`") unless auth_data.has_key?(:oidc_auth_code) raise ArgumentError.new("`auth_data[:oidc_auth_code]` must be a String") unless auth_data[:oidc_auth_code].is_a?(String) raise ArgumentError.new("`auth_data` must contain key `:redirect_uri`") unless auth_data.has_key?(:redirect_uri) raise ArgumentError.new("`auth_data[:redirect_uri]` must be a String") unless auth_data[:redirect_uri].is_a?(String) params = {phone_number: phone_number} - params[:hashed_phone_number] = params.delete(:phone_number) if hashed == true request( '/camara/number-verification/v031/verify', diff --git a/test/vonage/network_number_verification_test.rb b/test/vonage/network_number_verification_test.rb index a1ddd598..2597d281 100644 --- a/test/vonage/network_number_verification_test.rb +++ b/test/vonage/network_number_verification_test.rb @@ -49,30 +49,6 @@ def test_verify_method assert_kind_of Vonage::Response, response end - def test_verify_method_with_hashed_phone_number - request_access_token_request_params = { - grant_type: 'authorization_code', - code: example_oidc_auth_code, - redirect_uri: example_redirect_uri - } - - number_verification_verify_params = {hashedPhoneNumber: hashed_phone_number} - - stub_request(:post, "https://api-eu.vonage.com/oauth2/token").with(request(body: request_access_token_request_params, headers: headers)).to_return(network_authentication_token_response) - stub_request(:post, uri + '/verify').with(body: number_verification_verify_params).to_return(response) - - response = network_number_verification.verify( - phone_number: hashed_phone_number, - hashed: true, - auth_data: { - oidc_auth_code: example_oidc_auth_code, - redirect_uri: example_redirect_uri - } - ) - - assert_kind_of Vonage::Response, response - end - def test_verify_method_without_phone_number assert_raises(ArgumentError) do network_number_verification.verify( @@ -95,15 +71,6 @@ def test_verify_method_with_invalid_phone_number assert_raises(ArgumentError) { network_number_verification.verify(phone_number: '447904603505', auth_data: auth_data) } end - def test_verify_method_with_invalid_hashed - auth_data = { - oidc_auth_code: example_oidc_auth_code, - redirect_uri: example_redirect_uri - } - - assert_raises(TypeError) { network_number_verification.verify(phone_number: hashed_phone_number, auth_data: auth_data, hashed: 'true') } - end - def test_verify_method_without_auth_data assert_raises(ArgumentError) { network_number_verification.verify(phone_number: phone_number) } end