|
10 | 10 | }
|
11 | 11 | EOS
|
12 | 12 |
|
| 13 | +ISSUE_CHANNEL_ACCESS_TOKEN_21_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_21_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 | WebMock.allow_net_connect!
|
14 | 36 |
|
15 | 37 | describe Line::Bot::Client do
|
@@ -51,4 +73,41 @@ def generate_client
|
51 | 73 |
|
52 | 74 | expect(response).to be_a(Net::HTTPOK)
|
53 | 75 | end
|
| 76 | + |
| 77 | + it 'issues an oauth access token v2.1' do |
| 78 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/oauth2/v2.1/token' |
| 79 | + stub_request(:post, uri_template).to_return { |request| {body: ISSUE_CHANNEL_ACCESS_TOKEN_21_CONTENT, status: 200} } |
| 80 | + |
| 81 | + client = generate_client |
| 82 | + response = client.issue_channel_access_token_21('jwt_string') |
| 83 | + |
| 84 | + expect(response).to be_a(Net::HTTPOK) |
| 85 | + result = JSON.parse(response.body) |
| 86 | + expect(result['access_token']).to eq 'eyJhbGciOiJIUzxxxxxx' |
| 87 | + expect(result['expires_in']).to eq 2592000 |
| 88 | + expect(result['token_type']).to eq 'Bearer' |
| 89 | + expect(result['key_id']).to eq 'sDTOzw5wIfxxxxPEzcmeQA' |
| 90 | + end |
| 91 | + |
| 92 | + it 'revokes the oauth access token v2.1' do |
| 93 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/oauth2/v2.1/revoke' |
| 94 | + stub_request(:post, uri_template).to_return { |request| {body: '', status: 200} } |
| 95 | + |
| 96 | + client = generate_client |
| 97 | + |
| 98 | + response = client.revoke_channel_access_token_21('sDTOzw5wIfxxxxPEzcmeQA'): |
| 99 | + |
| 100 | + expect(response).to be_a(Net::HTTPOK) |
| 101 | + end |
| 102 | + |
| 103 | + it 'get all valid channel access token key ids v2.1' do |
| 104 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/oauth2/v2.1/tokens/kid' |
| 105 | + stub_request(:post, uri_template).to_return { |request| {body: GET_CHANNEL_ACCESS_TOKEN_KEY_IDS_21_CONTENT, status: 200} } |
| 106 | + |
| 107 | + client = generate_client |
| 108 | + |
| 109 | + response = client.get_channel_access_token_key_ids_21('jwt_string') |
| 110 | + |
| 111 | + expect(response).to be_a(Net::HTTPOK) |
| 112 | + end |
54 | 113 | end
|
0 commit comments