(options?: { readonly tokenExpiresInSeconds?: number })
| 2150 | |
| 2151 | /** Mint a connection against `server` and return the harness + call log. */ |
| 2152 | const connectRejecting = (options?: { readonly tokenExpiresInSeconds?: number }) => |
| 2153 | Effect.gen(function* () { |
| 2154 | const server = yield* serveOAuthTestServer({ |
| 2155 | scopes: ["read"], |
| 2156 | ...(options?.tokenExpiresInSeconds !== undefined |
| 2157 | ? { tokenExpiresInSeconds: options.tokenExpiresInSeconds } |
| 2158 | : {}), |
| 2159 | }); |
| 2160 | const state = { |
| 2161 | revoked: new Set<string>(), |
| 2162 | rejectEverything: false, |
| 2163 | calls: [] as string[], |
| 2164 | }; |
| 2165 | const issuedLatest = Effect.gen(function* () { |
| 2166 | const issued = yield* server.issuedAccessTokens; |
| 2167 | return issued.length > 0 ? issued[issued.length - 1]! : null; |
| 2168 | }); |
| 2169 | const harness = yield* makeTestWorkspaceHarness({ |
| 2170 | plugins: [memoryCredentialsPlugin(), makeRejectingPlugin(state)] as const, |
| 2171 | }); |
| 2172 | const { executor, config } = harness; |
| 2173 | yield* executor.acme.seed(); |
| 2174 | yield* executor.oauth.createClient({ |
| 2175 | owner: "org", |
| 2176 | slug: CLIENT, |
| 2177 | authorizationUrl: server.authorizationEndpoint, |
| 2178 | tokenUrl: server.tokenEndpoint, |
| 2179 | grant: "authorization_code", |
| 2180 | clientId: "test-client", |
| 2181 | clientSecret: "test-secret", |
| 2182 | }); |
| 2183 | const started = yield* executor.oauth.start({ |
| 2184 | owner: "org", |
| 2185 | client: CLIENT, |
| 2186 | clientOwner: "org", |
| 2187 | name: ConnectionName.make("mine"), |
| 2188 | integration: INTEG, |
| 2189 | template: TEMPLATE, |
| 2190 | }); |
| 2191 | if (started.status !== "redirect") { |
| 2192 | return yield* Effect.die("expected a redirect-status OAuth start"); |
| 2193 | } |
| 2194 | const callback = yield* server.completeAuthorizationCodeFlow({ |
| 2195 | authorizationUrl: started.authorizationUrl, |
| 2196 | }); |
| 2197 | yield* executor.oauth.complete({ state: started.state, code: callback.code }); |
| 2198 | return { server, state, executor, config, issuedLatest }; |
| 2199 | }); |
| 2200 | |
| 2201 | const ADDRESS = ToolAddress.make("tools.acme.org.mine.whoami"); |
| 2202 |
no test coverage detected