|
10 | 10 | } |
11 | 11 | EOS |
12 | 12 |
|
| 13 | +ISSUE_CHANNEL_ACCESS_TOKEN_JWT_CONTENT = <<"EOS" |
| 14 | +{ |
| 15 | + "access_token": "eyJhbGciOiJIUzxxxxxx", |
| 16 | + "token_type": "Bearer", |
| 17 | + "expires_in": 2592000, |
| 18 | + "key_id": "sDTOzw5wIfxxxxPEzcmeQA" |
| 19 | +} |
| 20 | +EOS |
| 21 | + |
| 22 | +GET_CHANNEL_ACCESS_TOKEN_KEY_IDS_JWT_CONTENT = <<"EOS" |
| 23 | +{ |
| 24 | + "key_ids": [ |
| 25 | + "U_gdnFYKTWRxxxxDVZexGg", |
| 26 | + "sDTOzw5wIfWxxxxzcmeQA", |
| 27 | + "73hDyp3PxGfxxxxD6U5qYA", |
| 28 | + "FHGanaP79smDxxxxyPrVw", |
| 29 | + "CguB-0kxxxxdSM3A5Q_UtQ", |
| 30 | + "G82YP96jhHwyKSxxxx7IFA" |
| 31 | + ] |
| 32 | +} |
| 33 | +EOS |
| 34 | + |
13 | 35 | describe Line::Bot::Client do |
14 | 36 | def dummy_config |
15 | 37 | { |
@@ -49,4 +71,45 @@ def generate_client |
49 | 71 |
|
50 | 72 | expect(response).to be_a(Net::HTTPOK) |
51 | 73 | end |
| 74 | + |
| 75 | + it 'issues an oauth access token v2.1' do |
| 76 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_OAUTH_ENDPOINT + '/oauth2/v2.1/token' |
| 77 | + stub_request(:post, uri_template).to_return { |request| {body: ISSUE_CHANNEL_ACCESS_TOKEN_JWT_CONTENT, status: 200} } |
| 78 | + |
| 79 | + client = generate_client |
| 80 | + response = client.issue_channel_access_token_jwt('jwt_string') |
| 81 | + |
| 82 | + expect(response).to be_a(Net::HTTPOK) |
| 83 | + result = JSON.parse(response.body) |
| 84 | + expect(result['access_token']).to eq 'eyJhbGciOiJIUzxxxxxx' |
| 85 | + expect(result['expires_in']).to eq 2592000 |
| 86 | + expect(result['token_type']).to eq 'Bearer' |
| 87 | + expect(result['key_id']).to eq 'sDTOzw5wIfxxxxPEzcmeQA' |
| 88 | + end |
| 89 | + |
| 90 | + it 'revokes the oauth access token v2.1' do |
| 91 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_OAUTH_ENDPOINT + '/oauth2/v2.1/revoke' |
| 92 | + stub_request(:post, uri_template).to_return { |request| {body: '', status: 200} } |
| 93 | + |
| 94 | + client = generate_client |
| 95 | + |
| 96 | + response = client.revoke_channel_access_token_jwt('sDTOzw5wIfxxxxPEzcmeQA') |
| 97 | + |
| 98 | + expect(response).to be_a(Net::HTTPOK) |
| 99 | + end |
| 100 | + |
| 101 | + it 'get all valid channel access token key ids v2.1' do |
| 102 | + client_assertion = 'jwt_string' |
| 103 | + client_assertion_type = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer' |
| 104 | + |
| 105 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_OAUTH_ENDPOINT + |
| 106 | + "/oauth2/v2.1/tokens/kid?client_assertion=#{client_assertion}&client_assertion_type=#{client_assertion_type}" |
| 107 | + stub_request(:any, uri_template).to_return { |request| {body: GET_CHANNEL_ACCESS_TOKEN_KEY_IDS_JWT_CONTENT, status: 200} } |
| 108 | + |
| 109 | + client = generate_client |
| 110 | + |
| 111 | + response = client.get_channel_access_token_key_ids_jwt('jwt_string') |
| 112 | + |
| 113 | + expect(response).to be_a(Net::HTTPOK) |
| 114 | + end |
52 | 115 | end |
0 commit comments