Make auth use JWTs.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3991 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-09-28 23:52:44 +00:00
parent 5b3ae3f006
commit 113a82b382
4 changed files with 232 additions and 36 deletions

View File

@ -585,6 +585,61 @@ static void _test_file(const tf_test_options_t* options)
unlink("out/test.js");
}
static void _test_sign(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
"'use strict';\n"
"let id = ssb.createIdentity('test');\n"
"print(id);\n"
"let sig = ssb.hmacsha256sign('hello', 'test', id);\n"
"print(sig);\n"
"if (!ssb.hmacsha256verify(id, 'hello', sig)) {\n"
" exit(1);\n"
"}\n"
"if (ssb.hmacsha256verify(id, 'world', sig)) {\n"
" exit(1);\n"
"}\n"
"if (ssb.hmacsha256verify(id, 'hello1', sig)) {\n"
" exit(1);\n"
"}\n"
);
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path);
printf("%s\n", command);
int result = system(command);
printf("returned %d\n", WEXITSTATUS(result));
assert(WIFEXITED(result));
assert(WEXITSTATUS(result) == 0);
unlink("out/test.js");
}
static void _test_b64(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
"'use strict';\n"
"print(base64Encode('hello'));\n"
"if (base64Decode(base64Encode('hello')) !== 'hello') {\n"
" exit(1);\n"
"}\n"
);
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path);
printf("%s\n", command);
int result = system(command);
printf("returned %d\n", WEXITSTATUS(result));
assert(WIFEXITED(result));
assert(WEXITSTATUS(result) == 0);
unlink("out/test.js");
}
static void _tf_test_run(const tf_test_options_t* options, const char* name, void (*test)(const tf_test_options_t* options))
{
bool specified = false;
@ -639,5 +694,7 @@ void tf_tests(const tf_test_options_t* options)
_tf_test_run(options, "uint8array", _test_uint8array);
_tf_test_run(options, "socket", _test_socket);
_tf_test_run(options, "file", _test_file);
_tf_test_run(options, "sign", _test_sign);
_tf_test_run(options, "b64", _test_b64);
printf("Tests completed.\n");
}