|
32 | 32 | }
|
33 | 33 | EOS
|
34 | 34 |
|
| 35 | +VERIFY_ID_TOKEN_CONTENT = <<"EOS" |
| 36 | +{ |
| 37 | + "iss": "https://access.line.me", |
| 38 | + "sub": "U1234567890abcdef1234567890abcdef", |
| 39 | + "aud": "1234567890", |
| 40 | + "exp": 1504169092, |
| 41 | + "iat": 1504263657, |
| 42 | + "nonce": "0987654asdf", |
| 43 | + "amr": ["pwd"], |
| 44 | + "name": "Taro Line", |
| 45 | + "picture": "https://sample_line.me/aBcdefg123456", |
| 46 | + |
| 47 | +} |
| 48 | +EOS |
| 49 | + |
| 50 | +VERIFY_ACCESS_TOKEN_CONTENT = <<"EOS" |
| 51 | +{ |
| 52 | + "scope": "profile", |
| 53 | + "client_id": "1440057261", |
| 54 | + "expires_in": 2591659 |
| 55 | +} |
| 56 | +EOS |
| 57 | + |
| 58 | +PROFILE_BY_ACCESS_TOKEN_CONTENT = <<"EOS" |
| 59 | +{ |
| 60 | + "userId": "U4af4980629...", |
| 61 | + "displayName": "Brown", |
| 62 | + "pictureUrl": "https://profile.line-scdn.net/abcdefghijklmn", |
| 63 | + "statusMessage": "Hello, LINE!" |
| 64 | +} |
| 65 | +EOS |
| 66 | + |
35 | 67 | describe Line::Bot::Client do
|
36 | 68 | def dummy_config
|
37 | 69 | {
|
@@ -112,4 +144,41 @@ def generate_client
|
112 | 144 |
|
113 | 145 | expect(response).to be_a(Net::HTTPOK)
|
114 | 146 | end
|
| 147 | + |
| 148 | + it 'verifies ID token' do |
| 149 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_OAUTH_ENDPOINT + '/oauth2/v2.1/verify' |
| 150 | + stub_request(:post, uri_template) |
| 151 | + .with(body: { client_id: 'channel id', id_token: 'dummy_id_token', nonce: 'dummy_nonce'}) |
| 152 | + .to_return { |request| {body: VERIFY_ID_TOKEN_CONTENT, status: 200} } |
| 153 | + |
| 154 | + client = generate_client |
| 155 | + |
| 156 | + response = client.verify_id_token('dummy_id_token', nonce: 'dummy_nonce') |
| 157 | + |
| 158 | + expect(response).to be_a(Net::HTTPOK).and(have_attributes(body: VERIFY_ID_TOKEN_CONTENT)) |
| 159 | + end |
| 160 | + |
| 161 | + it 'verifies access token' do |
| 162 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_OAUTH_ENDPOINT + '/oauth2/v2.1/verify?access_token=dummy_access_token' |
| 163 | + stub_request(:get, uri_template).to_return { |request| {body: VERIFY_ACCESS_TOKEN_CONTENT, status: 200} } |
| 164 | + |
| 165 | + client = generate_client |
| 166 | + |
| 167 | + response = client.verify_access_token('dummy_access_token') |
| 168 | + |
| 169 | + expect(response).to be_a(Net::HTTPOK).and(have_attributes(body: VERIFY_ACCESS_TOKEN_CONTENT)) |
| 170 | + end |
| 171 | + |
| 172 | + it 'gets profile by access token' do |
| 173 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_OAUTH_ENDPOINT + '/v2/profile' |
| 174 | + stub_request(:get, uri_template) |
| 175 | + .with(headers: { 'Authorization' => 'Bearer dummy_access_token'}) |
| 176 | + .to_return { |request| {body: PROFILE_BY_ACCESS_TOKEN_CONTENT, status: 200} } |
| 177 | + |
| 178 | + client = generate_client |
| 179 | + |
| 180 | + response = client.get_profile_by_access_token('dummy_access_token') |
| 181 | + |
| 182 | + expect(response).to be_a(Net::HTTPOK).and(have_attributes(body: PROFILE_BY_ACCESS_TOKEN_CONTENT)) |
| 183 | + end |
115 | 184 | end
|
0 commit comments