|
| 1 | +/* |
| 2 | + * Copyright 2023 LINE Corporation |
| 3 | + * |
| 4 | + * LINE Corporation licenses this file to you under the Apache License, |
| 5 | + * version 2.0 (the "License"); you may not use this file except in compliance |
| 6 | + * with the License. You may obtain a copy of the License at: |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations |
| 14 | + * under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +/** |
| 18 | + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). |
| 19 | + * https://openapi-generator.tech Do not edit the class manually. |
| 20 | + */ |
| 21 | +package com.linecorp.bot.oauth.client; |
| 22 | + |
| 23 | +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; |
| 24 | +import static com.github.tomakehurst.wiremock.client.WireMock.configureFor; |
| 25 | +import static com.github.tomakehurst.wiremock.client.WireMock.get; |
| 26 | +import static com.github.tomakehurst.wiremock.client.WireMock.post; |
| 27 | +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; |
| 28 | +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathTemplate; |
| 29 | +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; |
| 30 | +import static org.assertj.core.api.Assertions.assertThat; |
| 31 | + |
| 32 | +import com.github.tomakehurst.wiremock.WireMockServer; |
| 33 | +import com.linecorp.bot.oauth.model.ChannelAccessTokenKeyIdsResponse; |
| 34 | +import com.linecorp.bot.oauth.model.IssueChannelAccessTokenResponse; |
| 35 | +import com.linecorp.bot.oauth.model.IssueShortLivedChannelAccessTokenResponse; |
| 36 | +import com.linecorp.bot.oauth.model.IssueStatelessChannelAccessTokenResponse; |
| 37 | +import com.linecorp.bot.oauth.model.VerifyChannelAccessTokenResponse; |
| 38 | +import com.ocadotechnology.gembus.test.Arranger; |
| 39 | +import java.net.URI; |
| 40 | +import org.junit.jupiter.api.AfterEach; |
| 41 | +import org.junit.jupiter.api.BeforeEach; |
| 42 | +import org.junit.jupiter.api.Test; |
| 43 | +import org.junit.jupiter.api.Timeout; |
| 44 | +import org.slf4j.bridge.SLF4JBridgeHandler; |
| 45 | + |
| 46 | +/** API tests for ChannelAccessTokenClient */ |
| 47 | +@Timeout(5) |
| 48 | +public class ChannelAccessTokenClientTest { |
| 49 | + static { |
| 50 | + SLF4JBridgeHandler.removeHandlersForRootLogger(); |
| 51 | + SLF4JBridgeHandler.install(); |
| 52 | + } |
| 53 | + |
| 54 | + private WireMockServer wireMockServer; |
| 55 | + private ChannelAccessTokenClient api; |
| 56 | + |
| 57 | + @BeforeEach |
| 58 | + public void setUp() { |
| 59 | + wireMockServer = new WireMockServer(wireMockConfig().dynamicPort()); |
| 60 | + wireMockServer.start(); |
| 61 | + configureFor("localhost", wireMockServer.port()); |
| 62 | + |
| 63 | + api = |
| 64 | + ChannelAccessTokenClient.builder() |
| 65 | + .apiEndPoint(URI.create(wireMockServer.baseUrl())) |
| 66 | + .build(); |
| 67 | + } |
| 68 | + |
| 69 | + @AfterEach |
| 70 | + public void tearDown() { |
| 71 | + wireMockServer.stop(); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + public void getsAllValidChannelAccessTokenKeyIdsTest() { |
| 76 | + stubFor( |
| 77 | + get(urlPathTemplate("/oauth2/v2.1/tokens/kid")) |
| 78 | + .willReturn( |
| 79 | + aResponse() |
| 80 | + .withStatus(200) |
| 81 | + .withHeader("content-type", "application/json") |
| 82 | + .withBody("{}"))); |
| 83 | + |
| 84 | + String clientAssertionType = Arranger.some(String.class); |
| 85 | + |
| 86 | + String clientAssertion = Arranger.some(String.class); |
| 87 | + |
| 88 | + ChannelAccessTokenKeyIdsResponse response = |
| 89 | + api.getsAllValidChannelAccessTokenKeyIds(clientAssertionType, clientAssertion) |
| 90 | + .join() |
| 91 | + .body(); |
| 92 | + |
| 93 | + assertThat(response).isNotNull(); |
| 94 | + |
| 95 | + // TODO: test validations |
| 96 | + } |
| 97 | + |
| 98 | + @Test |
| 99 | + public void issueChannelTokenTest() { |
| 100 | + stubFor( |
| 101 | + post(urlPathTemplate("/v2/oauth/accessToken")) |
| 102 | + .willReturn( |
| 103 | + aResponse() |
| 104 | + .withStatus(200) |
| 105 | + .withHeader("content-type", "application/json") |
| 106 | + .withBody("{}"))); |
| 107 | + |
| 108 | + String grantType = Arranger.some(String.class); |
| 109 | + |
| 110 | + String clientId = Arranger.some(String.class); |
| 111 | + |
| 112 | + String clientSecret = Arranger.some(String.class); |
| 113 | + |
| 114 | + IssueShortLivedChannelAccessTokenResponse response = |
| 115 | + api.issueChannelToken(grantType, clientId, clientSecret).join().body(); |
| 116 | + |
| 117 | + assertThat(response).isNotNull(); |
| 118 | + |
| 119 | + // TODO: test validations |
| 120 | + } |
| 121 | + |
| 122 | + @Test |
| 123 | + public void issueChannelTokenByJWTTest() { |
| 124 | + stubFor( |
| 125 | + post(urlPathTemplate("/oauth2/v2.1/token")) |
| 126 | + .willReturn( |
| 127 | + aResponse() |
| 128 | + .withStatus(200) |
| 129 | + .withHeader("content-type", "application/json") |
| 130 | + .withBody("{}"))); |
| 131 | + |
| 132 | + String grantType = Arranger.some(String.class); |
| 133 | + |
| 134 | + String clientAssertionType = Arranger.some(String.class); |
| 135 | + |
| 136 | + String clientAssertion = Arranger.some(String.class); |
| 137 | + |
| 138 | + IssueChannelAccessTokenResponse response = |
| 139 | + api.issueChannelTokenByJWT(grantType, clientAssertionType, clientAssertion).join().body(); |
| 140 | + |
| 141 | + assertThat(response).isNotNull(); |
| 142 | + |
| 143 | + // TODO: test validations |
| 144 | + } |
| 145 | + |
| 146 | + @Test |
| 147 | + public void issueStatelessChannelTokenTest() { |
| 148 | + stubFor( |
| 149 | + post(urlPathTemplate("/oauth2/v3/token")) |
| 150 | + .willReturn( |
| 151 | + aResponse() |
| 152 | + .withStatus(200) |
| 153 | + .withHeader("content-type", "application/json") |
| 154 | + .withBody("{}"))); |
| 155 | + |
| 156 | + String grantType = Arranger.some(String.class); |
| 157 | + |
| 158 | + String clientAssertionType = Arranger.some(String.class); |
| 159 | + |
| 160 | + String clientAssertion = Arranger.some(String.class); |
| 161 | + |
| 162 | + String clientId = Arranger.some(String.class); |
| 163 | + |
| 164 | + String clientSecret = Arranger.some(String.class); |
| 165 | + |
| 166 | + IssueStatelessChannelAccessTokenResponse response = |
| 167 | + api.issueStatelessChannelToken( |
| 168 | + grantType, clientAssertionType, clientAssertion, clientId, clientSecret) |
| 169 | + .join() |
| 170 | + .body(); |
| 171 | + |
| 172 | + assertThat(response).isNotNull(); |
| 173 | + |
| 174 | + // TODO: test validations |
| 175 | + } |
| 176 | + |
| 177 | + @Test |
| 178 | + public void revokeChannelTokenTest() { |
| 179 | + stubFor( |
| 180 | + post(urlPathTemplate("/v2/oauth/revoke")) |
| 181 | + .willReturn( |
| 182 | + aResponse() |
| 183 | + .withStatus(200) |
| 184 | + .withHeader("content-type", "application/json") |
| 185 | + .withBody("{}"))); |
| 186 | + |
| 187 | + String accessToken = Arranger.some(String.class); |
| 188 | + |
| 189 | + api.revokeChannelToken(accessToken).join().body(); |
| 190 | + |
| 191 | + // TODO: test validations |
| 192 | + } |
| 193 | + |
| 194 | + @Test |
| 195 | + public void revokeChannelTokenByJWTTest() { |
| 196 | + stubFor( |
| 197 | + post(urlPathTemplate("/oauth2/v2.1/revoke")) |
| 198 | + .willReturn( |
| 199 | + aResponse() |
| 200 | + .withStatus(200) |
| 201 | + .withHeader("content-type", "application/json") |
| 202 | + .withBody("{}"))); |
| 203 | + |
| 204 | + String clientId = Arranger.some(String.class); |
| 205 | + |
| 206 | + String clientSecret = Arranger.some(String.class); |
| 207 | + |
| 208 | + String accessToken = Arranger.some(String.class); |
| 209 | + |
| 210 | + api.revokeChannelTokenByJWT(clientId, clientSecret, accessToken).join().body(); |
| 211 | + |
| 212 | + // TODO: test validations |
| 213 | + } |
| 214 | + |
| 215 | + @Test |
| 216 | + public void verifyChannelTokenTest() { |
| 217 | + stubFor( |
| 218 | + post(urlPathTemplate("/v2/oauth/verify")) |
| 219 | + .willReturn( |
| 220 | + aResponse() |
| 221 | + .withStatus(200) |
| 222 | + .withHeader("content-type", "application/json") |
| 223 | + .withBody("{}"))); |
| 224 | + |
| 225 | + String accessToken = Arranger.some(String.class); |
| 226 | + |
| 227 | + VerifyChannelAccessTokenResponse response = api.verifyChannelToken(accessToken).join().body(); |
| 228 | + |
| 229 | + assertThat(response).isNotNull(); |
| 230 | + |
| 231 | + // TODO: test validations |
| 232 | + } |
| 233 | + |
| 234 | + @Test |
| 235 | + public void verifyChannelTokenByJWTTest() { |
| 236 | + stubFor( |
| 237 | + get(urlPathTemplate("/oauth2/v2.1/verify")) |
| 238 | + .willReturn( |
| 239 | + aResponse() |
| 240 | + .withStatus(200) |
| 241 | + .withHeader("content-type", "application/json") |
| 242 | + .withBody("{}"))); |
| 243 | + |
| 244 | + String accessToken = Arranger.some(String.class); |
| 245 | + |
| 246 | + VerifyChannelAccessTokenResponse response = |
| 247 | + api.verifyChannelTokenByJWT(accessToken).join().body(); |
| 248 | + |
| 249 | + assertThat(response).isNotNull(); |
| 250 | + |
| 251 | + // TODO: test validations |
| 252 | + } |
| 253 | +} |
0 commit comments