|  | 
|  | 1 | +# typed: false | 
|  | 2 | +require_relative '../test' | 
|  | 3 | + | 
|  | 4 | +class Vonage::NetworkAuthentication::ServerTest < Vonage::Test | 
|  | 5 | +  def server | 
|  | 6 | +    Vonage::NetworkAuthentication::Server.new(config) | 
|  | 7 | +  end | 
|  | 8 | + | 
|  | 9 | +  def token_uri | 
|  | 10 | +    "https://api-eu.vonage.com/oauth2/token" | 
|  | 11 | +  end | 
|  | 12 | + | 
|  | 13 | +  def bc_authorize_uri | 
|  | 14 | +    "https://api-eu.vonage.com/oauth2/bc-authorize" | 
|  | 15 | +  end | 
|  | 16 | + | 
|  | 17 | +  def example_purpose | 
|  | 18 | +    'FraudPreventionAndDetection' | 
|  | 19 | +  end | 
|  | 20 | + | 
|  | 21 | +  def example_api_scope | 
|  | 22 | +    'check-sim-swap' | 
|  | 23 | +  end | 
|  | 24 | + | 
|  | 25 | +  def example_login_hint | 
|  | 26 | +    '+447700900000' | 
|  | 27 | +  end | 
|  | 28 | + | 
|  | 29 | +  def test_bc_authorize_method | 
|  | 30 | +    request_params = { | 
|  | 31 | +      scope: "openid+dpv:#{example_purpose}##{example_api_scope}", | 
|  | 32 | +      login_hint: example_login_hint | 
|  | 33 | +    } | 
|  | 34 | + | 
|  | 35 | +    stub_request(:post, bc_authorize_uri).with(request(body: request_params, headers: headers)).to_return(network_authentication_oicd_response) | 
|  | 36 | + | 
|  | 37 | +    response = server.bc_authorize(purpose: example_purpose, api_scope: example_api_scope, login_hint: example_login_hint) | 
|  | 38 | + | 
|  | 39 | +    assert_kind_of Vonage::Response, response | 
|  | 40 | +    assert_equal network_authentication_auth_request_id, response.auth_req_id | 
|  | 41 | +  end | 
|  | 42 | + | 
|  | 43 | +  def test_bc_authorize_method_without_purpose | 
|  | 44 | +    assert_raises(ArgumentError) { server.bc_authorize(api_scope: example_api_scope, login_hint: example_login_hint) } | 
|  | 45 | +  end | 
|  | 46 | + | 
|  | 47 | +  def test_bc_authorize_method_without_api_scope | 
|  | 48 | +    assert_raises(ArgumentError) { server.bc_authorize(purpose: example_purpose, login_hint: example_login_hint) } | 
|  | 49 | +  end | 
|  | 50 | + | 
|  | 51 | +  def test_bc_authorize_method_without_login_hint | 
|  | 52 | +    assert_raises(ArgumentError) { server.bc_authorize(purpose: example_purpose, api_scope: example_api_scope) } | 
|  | 53 | +  end | 
|  | 54 | + | 
|  | 55 | +  def test_request_access_token_method | 
|  | 56 | +    request_params = { | 
|  | 57 | +      grant_type: 'urn:openid:params:grant-type:ciba', | 
|  | 58 | +      auth_req_id: network_authentication_auth_request_id | 
|  | 59 | +    } | 
|  | 60 | + | 
|  | 61 | +    stub_request(:post, token_uri).with(request(body: request_params, headers: headers)).to_return(network_authentication_token_response) | 
|  | 62 | + | 
|  | 63 | +    response = server.request_access_token(auth_req_id: network_authentication_auth_request_id) | 
|  | 64 | + | 
|  | 65 | +    assert_kind_of Vonage::Response, response | 
|  | 66 | +    assert_equal sample_webhook_token, response.access_token | 
|  | 67 | +  end | 
|  | 68 | + | 
|  | 69 | +  def test_request_access_token_method_without_auth_req_id | 
|  | 70 | +    assert_raises(ArgumentError) { server.request_access_token } | 
|  | 71 | +  end | 
|  | 72 | + | 
|  | 73 | +  def test_token_method | 
|  | 74 | +    bc_authorize_request_params = { | 
|  | 75 | +      scope: "openid+dpv:#{example_purpose}##{example_api_scope}", | 
|  | 76 | +      login_hint: example_login_hint | 
|  | 77 | +    } | 
|  | 78 | + | 
|  | 79 | +    request_access_token_request_params = { | 
|  | 80 | +      grant_type: 'urn:openid:params:grant-type:ciba', | 
|  | 81 | +      auth_req_id: network_authentication_auth_request_id | 
|  | 82 | +    } | 
|  | 83 | + | 
|  | 84 | +    stub_request(:post, bc_authorize_uri).with(request(body: bc_authorize_request_params, headers: headers)).to_return(network_authentication_oicd_response) | 
|  | 85 | +    stub_request(:post, token_uri).with(request(body: request_access_token_request_params, headers: headers)).to_return(network_authentication_token_response) | 
|  | 86 | + | 
|  | 87 | +    assert_equal sample_webhook_token, server.token(purpose: example_purpose, api_scope: example_api_scope, login_hint: example_login_hint) | 
|  | 88 | +  end | 
|  | 89 | +end | 
0 commit comments