|
7 | 7 |
|
8 | 8 | import uri |
9 | 9 | import chronos, chronos/apps/http/httpclient |
10 | | -import ../../libp2p/[autotls/acme/api, utils/opt] |
| 10 | +import ../../libp2p/autotls/acme/api |
11 | 11 |
|
12 | 12 | export api |
13 | 13 |
|
14 | 14 | type ACMEApiStub* = ref object of ACMEApi |
15 | 15 | ## Refuses every ACME request, recording what was requested. |
16 | | - stalls*: bool |
17 | 16 | requestedUris*: seq[Uri] |
18 | 17 |
|
19 | 18 | proc new*(T: typedesc[ACMEApiStub]): ACMEApiStub = |
20 | | - ACMEApiStub( |
21 | | - session: HttpSessionRef.new(), |
22 | | - directory: Opt.some( |
23 | | - ACMEDirectory( |
24 | | - newNonce: LetsEncryptURL & "/new-nonce", |
25 | | - newOrder: LetsEncryptURL & "/new-order", |
26 | | - newAccount: LetsEncryptURL & "/new-account", |
27 | | - ) |
28 | | - ), |
29 | | - acmeServerURL: parseUri(LetsEncryptURL), |
30 | | - ) |
31 | | - |
32 | | -method requestNonce*( |
33 | | - self: ACMEApiStub |
34 | | -): Future[Nonce] {.async: (raises: [ACMEError, CancelledError]).} = |
35 | | - Nonce($self.acmeServerURL & "/acme/1234") |
36 | | - |
37 | | -proc stallUntilCancelled(self: ACMEApiStub) {.async: (raises: [CancelledError]).} = |
38 | | - ## A request that only ends when the caller gives up on it. |
39 | | - await Future[void].Raising([CancelledError]).init("ACMEApiStub.request") |
| 19 | + ACMEApiStub(session: HttpSessionRef.new(), acmeServerURL: parseUri(LetsEncryptURL)) |
40 | 20 |
|
41 | 21 | proc refuse( |
42 | 22 | self: ACMEApiStub, uri: Uri |
43 | 23 | ): Future[HTTPResponse] {.async: (raises: [ACMEError, CancelledError]).} = |
44 | 24 | self.requestedUris.add(uri) |
45 | | - if self.stalls: |
46 | | - await self.stallUntilCancelled() |
47 | 25 | raise newException(ACMEError, "ACMEApiStub refused " & $uri) |
48 | 26 |
|
49 | 27 | method post*( |
|
0 commit comments