diff options
| author | Jesper Jensen <jesper@jnsn.dev> | 2026-10-04 23:51:01 +0200 |
|---|---|---|
| committer | Jesper Jensen <jesper@jnsn.dev> | 2026-10-04 23:51:01 +0200 |
| commit | 28f36a2e69e13ee326d8bda50ad7a8df4e74d63a (patch) | |
| tree | fe286a78f05be9424ba632e1ff33f581906b283a /test/auth.c | |
| parent | 2ed7bfe9bffecb9b6f6111b727b593a72d7bbc15 (diff) | |
| download | librm-28f36a2e69e13ee326d8bda50ad7a8df4e74d63a.tar.gz librm-28f36a2e69e13ee326d8bda50ad7a8df4e74d63a.zip | |
Saving done
Diffstat (limited to 'test/auth.c')
| -rw-r--r-- | test/auth.c | 85 |
1 files changed, 45 insertions, 40 deletions
diff --git a/test/auth.c b/test/auth.c index 40e2678..1a31ae4 100644 --- a/test/auth.c +++ b/test/auth.c @@ -1,48 +1,11 @@ #include <assert.h> -#include <stdio.h> -#include <transport.h> +#include <transport_test.h> #include <auth.h> #include <auth.h> #include "api.h" -struct ExpectedRequest { - bool ignore; - char *url; - char *token; - char *reqBody; - - struct SizedBlock retBody; - enum ReturnCode rc; -}; - -struct ExpectedRequest *nextResult = NULL; - -enum ReturnCode transport_request(char *url, char *token, char *reqBody, struct SizedBlock *retBody) { - assert(nextResult != NULL); - assert(strcmp(nextResult->url, url) == 0); - if(nextResult->reqBody == NULL) { - assert(nextResult->reqBody == NULL); - } else { - assert(reqBody != NULL); - assert(strcmp(nextResult->reqBody, reqBody) == 0); - } - - if(nextResult->token == NULL) { - assert(nextResult->token == NULL); - } else { - assert(token != NULL); - assert(strcmp(nextResult->token, token) == 0); - } - - - memcpy(retBody, &nextResult->retBody, sizeof(struct SizedBlock)); - - enum ReturnCode rc = nextResult->rc; - nextResult++; - return rc; -} - +extern struct ExpectedRequest *nextResult; #define STATIC_SIZED_BLOCK(str) {.size = sizeof(str), .memory = strdup(str)} int main() { @@ -95,7 +58,7 @@ int main() { char *code = "123456"; struct RMDevice device = { - .id = "5E35708B-59B6-4715-A5D8-576C741D8276" + .id = "5E35708B-59B6-4715-A5D8-576C741D8276", }; rc = rm_device_open(&device, code); assert(rc == RC_SUCCESS); @@ -140,5 +103,47 @@ int main() { // @COMPLETE We currently don't check that all the requests fired } + nextResult = (struct ExpectedRequest[]) { + { + .url = "https://internal.cloud.remarkable.com/sync/v4/root", + .token = "SomeUserToken", + .reqBody = NULL, + .retBody = STATIC_SIZED_BLOCK("{\"hash\": \"0000000000000000000000000000000000000000000000000000000000000000\", \"generation\": 1}"), + .rc = RC_SUCCESS, + }, + { + .url = "https://internal.cloud.remarkable.com/sync/v4/files/0000000000000000000000000000000000000000000000000000000000000000", + .token = "SomeUserToken", + .reqBody = NULL, + .retBody = STATIC_SIZED_BLOCK( + "3\n" + "0000000000000000000000000000000000000000000000000000000000000001:CollectionType:someId:1:0\n" + ), + .rc = RC_SUCCESS, + }, + }; + + { + enum ReturnCode rc; + + struct RMDevice device = { + .userToken = strdup("SomeUserToken"), + .deviceToken = strdup("SomeDeviceToken"), + }; + rc = rm_device_reopen(&device); + assert(rc == RC_SUCCESS); + + assert(memcmp(device.root, "0000000000000000000000000000000000000000000000000000000000000000", sizeof(device.root)) == 0); + assert(device.generation == 1); + + struct RMDir dir = {}; + rc = rm_dir_root(&device, &dir); + assert(rc == RC_SUCCESS); + + rm_device_close(&device); + + // @COMPLETE We currently don't check that all the requests fired + } + return 0; } |
