summaryrefslogtreecommitdiff
path: root/regress/lib/libradius/test20.c
blob: 592a9d1e1a3a1c45921c02c75be497f5da04ae61 (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
#include "incs.h"

/*
 * string attributes
 */

void test20(void)
{
	RADIUS_PACKET *packet;
	char buf[256];

	static const uint8_t attrs[] = {
		10, 12, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',
		RADIUS_TYPE_VENDOR_SPECIFIC, 17, 0, 0, 0, 20, 30, 11, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l',
		40, 7, 'z', 'x', 'c', 'v', 0,
		RADIUS_TYPE_VENDOR_SPECIFIC, 12, 0, 0, 0, 50, 60, 6, 'b', 'n', 0, 'm',
	};

	packet = radius_new_request_packet(RADIUS_CODE_ACCESS_REQUEST);

	radius_put_string_attr(packet, 10, "qwertyuiop");
	radius_put_vs_string_attr(packet, 20, 30, "asdfghjkl");
	radius_put_raw_attr(packet, 40, "zxcv\0", 5);
	radius_put_vs_raw_attr(packet, 50, 60, "bn\0m", 4);

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

	CHECK(radius_get_string_attr(packet, 10, buf, sizeof(buf)) == 0);
	CHECK(strcmp(buf, "qwertyuiop") == 0);

	CHECK(radius_get_vs_string_attr(packet, 20, 30, buf, sizeof(buf)) == 0);
	CHECK(strcmp(buf, "asdfghjkl") == 0);

	CHECK(radius_get_string_attr(packet, 40, buf, sizeof(buf)) != 0);
	CHECK(radius_get_vs_string_attr(packet, 50, 60, buf, sizeof(buf)) != 0);

	CHECK(radius_get_string_attr(packet, 10, buf, 4) == 0);
	CHECK(strcmp(buf, "qwe") == 0);

	CHECK(radius_get_vs_string_attr(packet, 20, 30, buf, 5) == 0);
	CHECK(strcmp(buf, "asdf") == 0);

	CHECK(radius_get_string_attr(packet, 10, buf, 0) == 0);
	CHECK(buf[0] != 0);

	CHECK(radius_get_vs_string_attr(packet, 20, 30, buf, 0) == 0);
	CHECK(buf[0] != 0);
}

ADD_TEST(test20)