Skip to content

Commit f9bb0b3

Browse files
committed
Updating network number verification tests
1 parent a48aa48 commit f9bb0b3

File tree

4 files changed

+55
-21
lines changed

4 files changed

+55
-21
lines changed

Diff for: lib/vonage/network_number_verification.rb

+14
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,19 @@ def verify(phone_number:, auth_data:, hashed: false)
5353
}
5454
)
5555
end
56+
57+
sig { params(phone_number: String, redirect_uri: String, state: T.nilable(String)).returns(String) }
58+
def generate_oidc_uri(phone_number:, redirect_uri:, state: nil)
59+
params = {
60+
purpose: 'FraudPreventionAndDetection',
61+
api_scope: 'number-verification-verify-read',
62+
login_hint: phone_number,
63+
redirect_uri: redirect_uri
64+
}
65+
66+
params[:state] = state if state
67+
68+
Vonage::NetworkAuthentication::ClientAuthentication.new(@config).generate_oidc_uri(**params)
69+
end
5670
end
5771
end

Diff for: test/vonage/network_authentication/client_authentication_test.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require_relative '../test'
33

44
class Vonage::NetworkAuthentication::ClientAuthenticationTest < Vonage::Test
5-
def client
5+
def client_authentication
66
Vonage::NetworkAuthentication::ClientAuthentication.new(config)
77
end
88

@@ -39,19 +39,19 @@ def test_token_method
3939

4040
stub_request(:post, token_uri).with(request(body: request_params, headers: headers)).to_return(network_authentication_token_response)
4141

42-
assert_equal sample_webhook_token, client.token(oidc_auth_code: example_oidc_auth_code, redirect_uri: example_redirect_uri)
42+
assert_equal sample_webhook_token, client_authentication.token(oidc_auth_code: example_oidc_auth_code, redirect_uri: example_redirect_uri)
4343
end
4444

4545
def test_token_method_without_oidc_auth_code
46-
assert_raises(ArgumentError) { client.token(redirect_uri: example_redirect_uri) }
46+
assert_raises(ArgumentError) { client_authentication.token(redirect_uri: example_redirect_uri) }
4747
end
4848

4949
def test_token_method_without_redirect_uri
50-
assert_raises(ArgumentError) { client.token(oidc_auth_code: example_oidc_auth_code) }
50+
assert_raises(ArgumentError) { client_authentication.token(oidc_auth_code: example_oidc_auth_code) }
5151
end
5252

5353
def test_generate_oidc_uri_method
54-
uri = client.generate_oidc_uri(
54+
uri = client_authentication.generate_oidc_uri(
5555
purpose: example_purpose,
5656
api_scope: example_api_scope,
5757
login_hint: example_login_hint,
@@ -62,7 +62,7 @@ def test_generate_oidc_uri_method
6262
end
6363

6464
def test_generate_oidc_uri_method_with_optional_params
65-
uri = client.generate_oidc_uri(
65+
uri = client_authentication.generate_oidc_uri(
6666
purpose: example_purpose,
6767
api_scope: example_api_scope,
6868
login_hint: example_login_hint,
@@ -74,18 +74,18 @@ def test_generate_oidc_uri_method_with_optional_params
7474
end
7575

7676
def test_generate_oidc_uri_method_without_purpose
77-
assert_raises(ArgumentError) { client.generate_oidc_uri(api_scope: example_api_scope, login_hint: example_login_hint, redirect_uri: example_redirect_uri) }
77+
assert_raises(ArgumentError) { client_authentication.generate_oidc_uri(api_scope: example_api_scope, login_hint: example_login_hint, redirect_uri: example_redirect_uri) }
7878
end
7979

8080
def test_generate_oidc_uri_method_without_api_scope
81-
assert_raises(ArgumentError) { client.generate_oidc_uri(purpose: example_purpose, login_hint: example_login_hint, redirect_uri: example_redirect_uri) }
81+
assert_raises(ArgumentError) { client_authentication.generate_oidc_uri(purpose: example_purpose, login_hint: example_login_hint, redirect_uri: example_redirect_uri) }
8282
end
8383

8484
def test_generate_oidc_uri_method_without_login_hint
85-
assert_raises(ArgumentError) { client.generate_oidc_uri(purpose: example_purpose, api_scope: example_api_scope, redirect_uri: example_redirect_uri) }
85+
assert_raises(ArgumentError) { client_authentication.generate_oidc_uri(purpose: example_purpose, api_scope: example_api_scope, redirect_uri: example_redirect_uri) }
8686
end
8787

8888
def test_generate_oidc_uri_method_without_redirect_uri
89-
assert_raises(ArgumentError) { client.generate_oidc_uri(purpose: example_purpose, api_scope: example_api_scope, login_hint: example_login_hint) }
89+
assert_raises(ArgumentError) { client_authentication.generate_oidc_uri(purpose: example_purpose, api_scope: example_api_scope, login_hint: example_login_hint) }
9090
end
9191
end

Diff for: test/vonage/network_authentication/server_authentication_test.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require_relative '../test'
33

44
class Vonage::NetworkAuthentication::ServerAuthenticationTest < Vonage::Test
5-
def server
5+
def server_authentication
66
Vonage::NetworkAuthentication::ServerAuthentication.new(config)
77
end
88

@@ -34,22 +34,22 @@ def test_bc_authorize_method
3434

3535
stub_request(:post, bc_authorize_uri).with(request(body: request_params, headers: headers)).to_return(network_authentication_oicd_response)
3636

37-
response = server.bc_authorize(purpose: example_purpose, api_scope: example_api_scope, login_hint: example_login_hint)
37+
response = server_authentication.bc_authorize(purpose: example_purpose, api_scope: example_api_scope, login_hint: example_login_hint)
3838

3939
assert_kind_of Vonage::Response, response
4040
assert_equal network_authentication_auth_request_id, response.auth_req_id
4141
end
4242

4343
def test_bc_authorize_method_without_purpose
44-
assert_raises(ArgumentError) { server.bc_authorize(api_scope: example_api_scope, login_hint: example_login_hint) }
44+
assert_raises(ArgumentError) { server_authentication.bc_authorize(api_scope: example_api_scope, login_hint: example_login_hint) }
4545
end
4646

4747
def test_bc_authorize_method_without_api_scope
48-
assert_raises(ArgumentError) { server.bc_authorize(purpose: example_purpose, login_hint: example_login_hint) }
48+
assert_raises(ArgumentError) { server_authentication.bc_authorize(purpose: example_purpose, login_hint: example_login_hint) }
4949
end
5050

5151
def test_bc_authorize_method_without_login_hint
52-
assert_raises(ArgumentError) { server.bc_authorize(purpose: example_purpose, api_scope: example_api_scope) }
52+
assert_raises(ArgumentError) { server_authentication.bc_authorize(purpose: example_purpose, api_scope: example_api_scope) }
5353
end
5454

5555
def test_request_access_token_method
@@ -60,14 +60,14 @@ def test_request_access_token_method
6060

6161
stub_request(:post, token_uri).with(request(body: request_params, headers: headers)).to_return(network_authentication_token_response)
6262

63-
response = server.request_access_token(auth_req_id: network_authentication_auth_request_id)
63+
response = server_authentication.request_access_token(auth_req_id: network_authentication_auth_request_id)
6464

6565
assert_kind_of Vonage::Response, response
6666
assert_equal sample_webhook_token, response.access_token
6767
end
6868

6969
def test_request_access_token_method_without_auth_req_id
70-
assert_raises(ArgumentError) { server.request_access_token }
70+
assert_raises(ArgumentError) { server_authentication.request_access_token }
7171
end
7272

7373
def test_token_method
@@ -84,18 +84,18 @@ def test_token_method
8484
stub_request(:post, bc_authorize_uri).with(request(body: bc_authorize_request_params, headers: headers)).to_return(network_authentication_oicd_response)
8585
stub_request(:post, token_uri).with(request(body: request_access_token_request_params, headers: headers)).to_return(network_authentication_token_response)
8686

87-
assert_equal sample_webhook_token, server.token(purpose: example_purpose, api_scope: example_api_scope, login_hint: example_login_hint)
87+
assert_equal sample_webhook_token, server_authentication.token(purpose: example_purpose, api_scope: example_api_scope, login_hint: example_login_hint)
8888
end
8989

9090
def test_token_method_without_purpose
91-
assert_raises(ArgumentError) { server.token(api_scope: example_api_scope, login_hint: example_login_hint) }
91+
assert_raises(ArgumentError) { server_authentication.token(api_scope: example_api_scope, login_hint: example_login_hint) }
9292
end
9393

9494
def test_token_method_without_api_scope
95-
assert_raises(ArgumentError) { server.token(purpose: example_purpose, login_hint: example_login_hint) }
95+
assert_raises(ArgumentError) { server_authentication.token(purpose: example_purpose, login_hint: example_login_hint) }
9696
end
9797

9898
def test_token_method_without_login_hint
99-
assert_raises(ArgumentError) { server.token(purpose: example_purpose, api_scope: example_api_scope) }
99+
assert_raises(ArgumentError) { server_authentication.token(purpose: example_purpose, api_scope: example_api_scope) }
100100
end
101101
end

Diff for: test/vonage/network_number_verification_test.rb

+20
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,24 @@ def test_check_method_with_invalid_redirect_uri
150150

151151
assert_raises(ArgumentError) { network_number_verification.verify(phone_number: phone_number, auth_data: auth_data) }
152152
end
153+
154+
def test_generate_client_uri_method
155+
expected_uri = "https://oidc.idp.vonage.com/oauth2/auth?client_id=#{application_id}&response_type=code&scope=openid+dpv:FraudPreventionAndDetection#number-verification-verify-read&login_hint=#{phone_number}&redirect_uri=#{example_redirect_uri}"
156+
157+
assert_equal expected_uri, network_number_verification.generate_oidc_uri(phone_number: phone_number, redirect_uri: example_redirect_uri)
158+
end
159+
160+
def test_generate_client_uri_method_with_optional_params
161+
expected_uri = "https://oidc.idp.vonage.com/oauth2/auth?client_id=#{application_id}&response_type=code&scope=openid+dpv:FraudPreventionAndDetection#number-verification-verify-read&login_hint=#{phone_number}&redirect_uri=#{example_redirect_uri}&state=12345"
162+
163+
assert_equal expected_uri, network_number_verification.generate_oidc_uri(phone_number: phone_number, redirect_uri: example_redirect_uri, state: '12345')
164+
end
165+
166+
def test_generate_client_uri_method_without_phone_number
167+
assert_raises(ArgumentError) { network_number_verification.generate_oidc_uri(redirect_uri: example_redirect_uri) }
168+
end
169+
170+
def test_generate_client_uri_method_without_redirect_uri
171+
assert_raises(ArgumentError) { network_number_verification.generate_oidc_uri(phone_number: phone_number) }
172+
end
153173
end

0 commit comments

Comments
 (0)