|
Packit |
fd8b60 |
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
Packit |
fd8b60 |
/* lib/krad/t_attr.c - Attribute test program */
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* Copyright 2013 Red Hat, Inc. All rights reserved.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* Redistribution and use in source and binary forms, with or without
|
|
Packit |
fd8b60 |
* modification, are permitted provided that the following conditions are met:
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* 1. Redistributions of source code must retain the above copyright
|
|
Packit |
fd8b60 |
* notice, this list of conditions and the following disclaimer.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
Packit |
fd8b60 |
* notice, this list of conditions and the following disclaimer in
|
|
Packit |
fd8b60 |
* the documentation and/or other materials provided with the
|
|
Packit |
fd8b60 |
* distribution.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
Packit |
fd8b60 |
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
Packit |
fd8b60 |
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
Packit |
fd8b60 |
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
|
Packit |
fd8b60 |
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
Packit |
fd8b60 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
Packit |
fd8b60 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
Packit |
fd8b60 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
Packit |
fd8b60 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
Packit |
fd8b60 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
Packit |
fd8b60 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#include "t_test.h"
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
const static unsigned char encoded[] = {
|
|
Packit |
fd8b60 |
0xba, 0xfc, 0xed, 0x50, 0xe1, 0xeb, 0xa6, 0xc3,
|
|
Packit |
fd8b60 |
0xc1, 0x75, 0x20, 0xe9, 0x10, 0xce, 0xc2, 0xcb
|
|
Packit |
fd8b60 |
};
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
const static unsigned char auth[] = {
|
|
Packit |
fd8b60 |
0xac, 0x9d, 0xc1, 0x62, 0x08, 0xc4, 0xc7, 0x8b,
|
|
Packit |
fd8b60 |
0xa1, 0x2f, 0x25, 0x0a, 0xc4, 0x1d, 0x36, 0x41
|
|
Packit |
fd8b60 |
};
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
int
|
|
Packit |
fd8b60 |
main()
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
unsigned char outbuf[MAX_ATTRSETSIZE];
|
|
Packit |
fd8b60 |
const char *decoded = "accept";
|
|
Packit |
fd8b60 |
const char *secret = "foo";
|
|
Packit |
fd8b60 |
krb5_error_code retval;
|
|
Packit |
fd8b60 |
krb5_context ctx;
|
|
Packit |
fd8b60 |
const char *tmp;
|
|
Packit |
fd8b60 |
krb5_data in;
|
|
Packit |
fd8b60 |
size_t len;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
noerror(krb5_init_context(&ctx));
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Make sure User-Name is 1. */
|
|
Packit |
fd8b60 |
insist(krad_attr_name2num("User-Name") == 1);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Make sure 2 is User-Password. */
|
|
Packit |
fd8b60 |
tmp = krad_attr_num2name(2);
|
|
Packit |
fd8b60 |
insist(tmp != NULL);
|
|
Packit |
fd8b60 |
insist(strcmp(tmp, "User-Password") == 0);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Test decoding. */
|
|
Packit |
fd8b60 |
in = make_data((void *)encoded, sizeof(encoded));
|
|
Packit |
fd8b60 |
noerror(kr_attr_decode(ctx, secret, auth,
|
|
Packit |
fd8b60 |
krad_attr_name2num("User-Password"),
|
|
Packit |
fd8b60 |
&in, outbuf, &len));
|
|
Packit |
fd8b60 |
insist(len == strlen(decoded));
|
|
Packit |
fd8b60 |
insist(memcmp(outbuf, decoded, len) == 0);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Test encoding. */
|
|
Packit |
fd8b60 |
in = string2data((char *)decoded);
|
|
Packit |
fd8b60 |
retval = kr_attr_encode(ctx, secret, auth,
|
|
Packit |
fd8b60 |
krad_attr_name2num("User-Password"),
|
|
Packit Bot |
805b76 |
&in, outbuf, &len;;
|
|
Packit |
fd8b60 |
insist(retval == 0);
|
|
Packit |
fd8b60 |
insist(len == sizeof(encoded));
|
|
Packit |
fd8b60 |
insist(memcmp(outbuf, encoded, len) == 0);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Test constraint. */
|
|
Packit |
fd8b60 |
in.length = 100;
|
|
Packit |
fd8b60 |
insist(kr_attr_valid(krad_attr_name2num("User-Password"), &in) == 0);
|
|
Packit |
fd8b60 |
in.length = 200;
|
|
Packit |
fd8b60 |
insist(kr_attr_valid(krad_attr_name2num("User-Password"), &in) != 0);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
krb5_free_context(ctx);
|
|
Packit |
fd8b60 |
return 0;
|
|
Packit |
fd8b60 |
}
|