summaryrefslogtreecommitdiff
path: root/regress/lib/libradius/test21.c
blob: 10b7e2f5fc9894f4185acf3d11f4193b16a058cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "incs.h"

/*
 * integer (uint16_t, uint32_t, uint64_t) attributes
 */

void test21(void)
{
	RADIUS_PACKET *packet;
	uint16_t v16;
	uint32_t v32;
	uint64_t v64;

	static const uint8_t attrs_beforeset[] = {
		1, 3, 0,
		10, 4, 0x12, 0x34,
		RADIUS_TYPE_VENDOR_SPECIFIC, 10, 0, 0, 0, 20, 30, 4, 0x43, 0x21,
		40, 6, 0x13, 0x57, 0x9b, 0xdf,
		RADIUS_TYPE_VENDOR_SPECIFIC, 12, 0, 0, 0, 50, 60, 6, 0x24, 0x68, 0xac, 0xe0,
		70, 10, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
		RADIUS_TYPE_VENDOR_SPECIFIC, 16, 0, 0, 0, 80, 90, 10, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
	};
	static const uint8_t attrs_afterset[] = {
		1, 3, 0,
		10, 4, 0x43, 0x21,
		RADIUS_TYPE_VENDOR_SPECIFIC, 10, 0, 0, 0, 20, 30, 4, 0x12, 0x34,
		40, 6, 0x24, 0x68, 0xac, 0xe0,
		RADIUS_TYPE_VENDOR_SPECIFIC, 12, 0, 0, 0, 50, 60, 6, 0x13, 0x57, 0x9b, 0xdf,
		70, 10, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
		RADIUS_TYPE_VENDOR_SPECIFIC, 16, 0, 0, 0, 80, 90, 10, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
	};

	packet = radius_new_request_packet(RADIUS_CODE_ACCESS_REQUEST);

	radius_put_raw_attr(packet, 1, "", 1); /* padding for UNalignment */
	radius_put_uint16_attr(packet, 10, 0x1234);
	radius_put_vs_uint16_attr(packet, 20, 30, 0x4321);
	radius_put_uint32_attr(packet, 40, 0x13579bdfU);
	radius_put_vs_uint32_attr(packet, 50, 60, 0x2468ace0U);
	radius_put_uint64_attr(packet, 70, 0x0123456789abcdefULL);
	radius_put_vs_uint64_attr(packet, 80, 90, 0xfedcba9876543210ULL);

	CHECK(radius_get_length(packet) == sizeof(attrs_beforeset) + 20);
	CHECK(memcmp(radius_get_data(packet) + 20, attrs_beforeset, sizeof(attrs_beforeset)) == 0);

	CHECK(radius_get_uint16_attr(packet, 10, &v16) == 0);
	CHECK(v16 == 0x1234);
	CHECK(radius_get_vs_uint16_attr(packet, 20, 30, &v16) == 0);
	CHECK(v16 == 0x4321);

	CHECK(radius_get_uint32_attr(packet, 40, &v32) == 0);
	CHECK(v32 == 0x13579bdfU);
	CHECK(radius_get_vs_uint32_attr(packet, 50, 60, &v32) == 0);
	CHECK(v32 == 0x2468ace0U);

	CHECK(radius_get_uint64_attr(packet, 70, &v64) == 0);
	CHECK(v64 == 0x0123456789abcdefULL);
	CHECK(radius_get_vs_uint64_attr(packet, 80, 90, &v64) == 0);
	CHECK(v64 == 0xfedcba9876543210ULL);

	CHECK(radius_set_uint16_attr(packet, 10, 0x4321) == 0);
	CHECK(radius_set_vs_uint16_attr(packet, 20, 30, 0x1234) == 0);
	CHECK(radius_set_uint32_attr(packet, 40, 0x2468ace0U) == 0);
	CHECK(radius_set_vs_uint32_attr(packet, 50, 60, 0x13579bdfU) == 0);
	CHECK(radius_set_uint64_attr(packet, 70, 0xfedcba9876543210ULL) == 0);
	CHECK(radius_set_vs_uint64_attr(packet, 80, 90, 0x0123456789abcdefULL) == 0);

	CHECK(radius_get_length(packet) == sizeof(attrs_afterset) + 20);
	CHECK(memcmp(radius_get_data(packet) + 20, attrs_afterset, sizeof(attrs_afterset)) == 0);

	CHECK(radius_get_uint16_attr(packet, 40, &v16) != 0);
	CHECK(radius_get_vs_uint16_attr(packet, 50, 60, &v16) != 0);
	CHECK(radius_get_uint32_attr(packet, 70, &v32) != 0);
	CHECK(radius_get_vs_uint32_attr(packet, 80, 90, &v32) != 0);
	CHECK(radius_get_uint64_attr(packet, 10, &v64) != 0);
	CHECK(radius_get_vs_uint64_attr(packet, 20, 30, &v64) != 0);
}

ADD_TEST(test21)