Skip to content

Commit

Permalink
Removing hashed option from network number verification
Browse files Browse the repository at this point in the history
  • Loading branch information
superchilled committed Aug 7, 2024
1 parent a972691 commit 9f21145
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 40 deletions.
11 changes: 4 additions & 7 deletions lib/vonage/network_number_verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
33 changes: 0 additions & 33 deletions test/vonage/network_number_verification_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit 9f21145

Please sign in to comment.