tests/libpakfire/file \
tests/libpakfire/httpclient \
tests/libpakfire/jail \
+ tests/libpakfire/jwt \
tests/libpakfire/key \
tests/libpakfire/log_buffer \
tests/libpakfire/log_file \
tests_libpakfire_jail_LDADD = \
$(TESTSUITE_LDADD)
+dist_tests_libpakfire_jwt_SOURCES = \
+ tests/libpakfire/jwt.c
+
+tests_libpakfire_jwt_CPPFLAGS = \
+ $(TESTSUITE_CPPFLAGS)
+
+tests_libpakfire_jwt_CFLAGS = \
+ $(TESTSUITE_CFLAGS)
+
+tests_libpakfire_jwt_LDFLAGS = \
+ $(TESTSUITE_CFLAGS)
+
+tests_libpakfire_jwt_LDADD = \
+ $(TESTSUITE_LDADD)
+
tests_libpakfire_key_SOURCES = \
tests/libpakfire/key.c
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2025 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+// json-c
+#include <json.h>
+
+#include <pakfire/jwt.h>
+#include <pakfire/util.h>
+
+#include "../testsuite.h"
+
+// This is a sample access token
+const char* ACCESS_TOKEN =
+ "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9."
+ "eyJzdWIiOiJtc0BJUEZJUkUuT1JHIiwidHlwIjoiYWNjZXNzIiwiaWF0IjoxNzUxMDA5NTU3LCJleHAiOjE3NTEwMTMxNTd9."
+ "FaqgeZBdnYjgQZqV3mtu2oC5agJmkUPuSVFFGBG-yAY";
+
+const char* INVALID_TOKEN = "THISISANINVALIDTOKEN";
+
+static int test_payload(const struct test* t) {
+ struct json_object* payload = NULL;
+ int r = EXIT_FAILURE;
+
+ // Try to decode an invalid token
+ ASSERT_ERROR(pakfire_jwt_payload(INVALID_TOKEN, &payload), EINVAL);
+
+ // Decode the token
+ ASSERT_SUCCESS(pakfire_jwt_payload(ACCESS_TOKEN, &payload));
+
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ if (payload)
+ json_object_put(payload);
+
+ return r;
+}
+
+static int test_expiry(const struct test* t) {
+ int r = EXIT_FAILURE;
+
+ // Extract the expiry time
+ ASSERT_EQUALS(pakfire_jwt_expires_at(ACCESS_TOKEN), 1751013157);
+
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ return r;
+}
+
+int main(int argc, const char* argv[]) {
+ testsuite_add_test(test_payload, 0);
+ testsuite_add_test(test_expiry, 0);
+
+ return testsuite_run(argc, argv);
+}