1 /*
2 * RFC 7519 Json Web Tokens
3 *
4 * Copyright (C) 2018, Linaro, Ltd
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 #include <zephyr/types.h>
21 #include <stdbool.h>
22 #include <zephyr/ztest.h>
23 #include <zephyr/data/json.h>
24 #include <zephyr/data/jwt.h>
25
26 extern unsigned char jwt_test_private_der[];
27 extern unsigned int jwt_test_private_der_len;
28
ZTEST(jwt_tests,test_jwt)29 ZTEST(jwt_tests, test_jwt)
30 {
31 /*
32 * TODO: This length should be computable, based on the length
33 * of the audience string.
34 */
35 char buf[460];
36 struct jwt_builder build;
37 int res;
38
39 res = jwt_init_builder(&build, buf, sizeof(buf));
40
41 zassert_equal(res, 0, "Setting up jwt");
42
43 res = jwt_add_payload(&build, 1530312026, 1530308426,
44 "iot-work-199419");
45 zassert_equal(res, 0, "Adding payload");
46
47 res = jwt_sign(&build, jwt_test_private_der, jwt_test_private_der_len);
48 zassert_equal(res, 0, "Signing payload");
49
50 zassert_equal(build.overflowed, false, "Not overflow");
51
52 printk("JWT:\n%s\n", buf);
53 printk("len: %zd\n", strlen(buf));
54 }
55
56 ZTEST_SUITE(jwt_tests, NULL, NULL, NULL, NULL, NULL);
57