Commit 7113eb82 authored by Youness Alaoui's avatar Youness Alaoui

Removing duplicate+outdated and unused test files

parent db2383ad
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2007 Nokia Corporation. All rights reserved.
* Contact: Rémi Denis-Courmont
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Rémi Denis-Courmont, Nokia
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include "bind.h"
//#include <netinet/in.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <netdb.h>
#include <string.h>
#include <assert.h>
#define ERR( str, exp ) \
if (exp) { perror (str); exit (1); }
#define ERRVAL( str, exp ) \
ERR ((str), ((errno = (exp)) != 0))
static void printaddr (const struct sockaddr *addr, socklen_t addrlen)
{
char hostbuf[NI_MAXHOST], servbuf[NI_MAXSERV];
int val = getnameinfo (addr, addrlen, hostbuf, sizeof (hostbuf),
servbuf, sizeof (servbuf),
NI_NUMERICHOST | NI_NUMERICSERV);
if (val)
puts (gai_strerror (val));
else
printf ("%s port %s\n", hostbuf, servbuf);
}
static int test (int family, const char *hostname)
{
struct addrinfo hints, *res;
memset (&hints, 0, sizeof (hints));
hints.ai_family = family;
hints.ai_socktype = SOCK_DGRAM;
int val = getaddrinfo (hostname, "3478", &hints, &res);
if (val)
{
fprintf (stderr, "%s: %s\n", hostname, gai_strerror (val));
return -1;
}
for (struct addrinfo *ptr = res; ptr != NULL; ptr = ptr->ai_next)
{
struct sockaddr_storage addr;
socklen_t addrlen = sizeof (addr);
stun_bind_t *ctx;
printf ("STUN server: ");
printaddr (ptr->ai_addr, ptr->ai_addrlen);
printf ("Auto discovery: ");
ERRVAL ("Test 1",
stun_bind_run (-1, ptr->ai_addr, ptr->ai_addrlen,
(struct sockaddr *)&addr, &addrlen));
printaddr ((struct sockaddr *)&addr, addrlen);
int fd = socket (ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);
printf ("UDP discovery : ");
ERR ("socket", fd == -1);
addrlen = sizeof (addr);
ERRVAL ("Test 2",
stun_bind_run (fd, ptr->ai_addr, ptr->ai_addrlen,
(struct sockaddr *)&addr, &addrlen));
printaddr ((struct sockaddr *)&addr, addrlen);
// Cancellation test
ERRVAL ("Test 3", stun_bind_start (&ctx, -1,
ptr->ai_addr, ptr->ai_addrlen));
stun_bind_cancel (ctx);
close (fd);
}
freeaddrinfo (res);
return 0;
}
static char bigaddr[1024];
int main (int argc, char *argv[])
{
const char *server = NULL;
int family = AF_UNSPEC;
for (int i = 1; i < argc; i++)
{
if (strcmp (argv[i], "--ipv4") == 0)
family = AF_INET;
else
if (strcmp (argv[i], "--ipv6") == 0)
family = AF_INET6;
else
server = argv[i];
}
alarm (60); // force failure in case of deadlock
errno = EINVAL;
ERR ("Error case 1", !stun_bind_run (-1, NULL, 0, NULL, NULL));
assert (sizeof (bigaddr) > sizeof (struct sockaddr_storage));
memset (bigaddr, 0, sizeof (bigaddr));
ERR ("Error case 2",
!stun_bind_start (&(stun_bind_t *){ NULL }, -1,
(struct sockaddr *)bigaddr, sizeof (bigaddr)));
if (test (family, server))
return 1;
return 0;
}
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2007 Nokia Corporation. All rights reserved.
* Contact: Rémi Denis-Courmont
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Rémi Denis-Courmont, Nokia
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include "stun-msg.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
static void fatal (const char *msg, ...)
{
va_list ap;
va_start (ap, msg);
vfprintf (stderr, msg, ap);
va_end (ap);
fputc ('\n', stderr);
exit (1);
}
static void
dynamic_check (const stun_msg_t *msg, size_t len)
{
size_t len2 = stun_validate (msg, len);
if ((len != len2) || (len2 & 3))
fatal ("Invalid message (%u, %u)\n",
(unsigned)len, (unsigned)len2);
if (!stun_demux (msg))
fatal ("Invalid message multiplexing");
printf ("Built message of %u bytes\n", (unsigned)len);
}
static size_t
finish_check (stun_msg_t *msg)
{
stun_msg_t mshort;
memcpy (&mshort, msg, sizeof (mshort));
size_t len = stun_finish (msg);
if (len == 0)
fatal ("Cannot finish message");
dynamic_check (msg, len);
if (stun_verify_password (&mshort, "toto") != ENOENT)
fatal ("Missing HMAC test failed");
size_t slen = stun_finish_short (&mshort, "ABCDE", "admin", "ABC", 3);
if (slen == 0)
fatal ("Cannot finish message with short-term creds");
dynamic_check (&mshort, slen);
if (stun_verify_password (&mshort, "admin") != 0)
fatal ("Valid HMAC test failed");
return len;
}
int main (void)
{
stun_msg_t msg;
stun_transid_t id;
stun_make_transid (id);
/* Request formatting test */
stun_init (&msg, STUN_REQUEST, STUN_BINDING, id);
finish_check (&msg);
if (memcmp (&msg, "\x00\x01", 2))
fatal ("Request formatting test failed");
/* Response formatting test */
stun_init_response (&msg, &msg);
finish_check (&msg);
if (memcmp (&msg, "\x01\x01", 2))
fatal ("Response formatting test failed");
return 0;
}
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2007 Nokia Corporation. All rights reserved.
* Contact: Rémi Denis-Courmont
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Rémi Denis-Courmont, Nokia
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include "stun-msg.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
static void fatal (const char *msg, ...)
{
va_list ap;
va_start (ap, msg);
vfprintf (stderr, msg, ap);
va_end (ap);
fputc ('\n', stderr);
exit (1);
}
static void
static_check (const uint8_t *msg, unsigned len)
{
unsigned i = 0;
do
{
size_t vlen = stun_validate (msg, i);
if ((vlen & 3) || (vlen != ((i >= len) * len)))
fatal ("%u/%u short message test failed", i, len);
}
while (i++ < (len + 4));
}
int main (void)
{
static const uint8_t simple_resp[] =
"\x15\x55\x00\x00"
"\x21\x12\xA4\x42" // cookie
"\x76\x54\x32\x10"
"\xfe\xdc\xba\x98"
"\x76\x54\x32\x10"
"\xaa\xbb\xcc\xdd"; //extra garbage
static const uint8_t old_ind[] =
"\x14\x55\x00\x00"
"\xfe\xdc\xba\x98" // NO cookie
"\x76\x54\x32\x10"
"\xfe\xdc\xba\x98"
"\x76\x54\x32\x10"; //extra garbage
static const uint8_t fpr_resp[] =
"\x15\x55\x00\x10"
"\x21\x12\xA4\x42" // cookie
"\x76\x54\x32\x10"
"\xfe\xdc\xba\x98"
"\x76\x54\x32\x10"
"\x00\x06\x00\x04" // dummy USERNAME header
"\x41\x42\x43\x44"
"\x80\x21\x00\x04" // FINGERPRINT header
"\xdc\x8d\xa7\x74" // CRC32
"\xcc\xdd\xee\xff"; // extra garbage
static const uint8_t bad1[32] =
"\x15\x55\x00\x08"
"\x21\x12\xA4\x42" // cookie
"\x76\x54\x32\x10"
"\xfe\xdc\xba\x98"
"\x76\x54\x32\x10"
"\x00\x06\x00\x05" // too big attribute for message
"\x11\x22\x33\x44"
"\x55\x66\x77\x88";
static const uint8_t bad2[24] =
"\x15\x55\x00\x05" // invalid message length
"\x21\x12\xA4\x42"
"\x76\x54\x32\x10"
"\xfe\xdc\xba\x98"
"\x76\x54\x32\x10"
"\x00\x06\x00\x01";
static const uint8_t bad3[27] =
"\x15\x55\x00\x08"
"\x21\x12\xA4\x42"
"\x76\x54\x32\x10"
"\xfe\xdc\xba\x98"
"\x76\x54\x32\x10"
"\x00\x06\x00\x03"
"\x11\x22\x33"; // missing padding
static const uint8_t bad_crc[] =
"\x15\x55\x00\x08"
"\x21\x12\xA4\x42"
"\x76\x54\x32\x10"
"\xfe\xdc\xba\x98"
"\x76\x54\x32\x10"
"\x80\x21\x00\x04" // FINGERPRINT header
"\x04\x91\xcd\x78"; // CRC32
static uint8_t bad_crc_offset[] =
"\x15\x55\x00\x10"
"\x21\x12\xA4\x42"
"\x76\x54\x32\x10"
"\xfe\xdc\xba\x98"
"\x20\x67\xc4\x09"
"\x80\x21\x00\x04" // FINGERPRINT header
"\x00\x00\x00\x00"
"\x00\x06\x00\x04"
"\x41\x42\x43\x44";
static const uint8_t transid[12] =
"\x76\x54\x32\x10\xfe\xdc\xba\x98\x76\x54\x32\x10";
static const uint8_t badid[12] =
"\x76\x54\x32\x10\xfe\xdc\xca\x98\x76\x54\x32\x10";
bool error;
if (stun_validate (NULL, 0) != 0)
fatal ("0 bytes test failed");
if (stun_validate ("\xf0", 1) >= 0)
fatal ("1 byte test failed");
static_check (simple_resp, 20);
static_check (old_ind, 20);
static_check (fpr_resp, 36);
if (stun_demux (simple_resp))
fatal ("Missing CRC test failed");
if (stun_demux (old_ind))
fatal ("Missing cookie test failed");
if (!stun_demux (fpr_resp))
fatal ("Good CRC test failed");
if (stun_demux (bad_crc))
fatal ("Bad CRC test failed");
if (stun_demux (bad_crc_offset))
fatal ("Bad CRC offset test failed");
if (stun_validate (bad1, sizeof (bad1)) >= 0)
fatal ("Badness 1 test failed");
if (stun_validate (bad2, sizeof (bad2)) >= 0)
fatal ("Badness 2 test failed");
if (stun_validate (bad3, sizeof (bad3)) != 0)
fatal ("Badness 3 test failed");
if (stun_get_class (simple_resp) != 3)
fatal ("Class test failed");
if (stun_get_method (simple_resp) != 0x525)
fatal ("Method test failed");
if (stun_match_answer (simple_resp, 0x524, transid, &error))
fatal ("Answer method mismatching test failed");
if (stun_match_answer (old_ind, 0x525, transid, &error))
fatal ("Answer class mismatching test failed");
if (stun_match_answer (simple_resp, 0x525, badid, &error))
fatal ("Answer transid mismatching test failed");
if (!stun_match_answer (simple_resp, 0x525, transid, &error))
fatal ("Answer matching test failed");
if (!error)
fatal ("Answer error flag test failed");
return 0;
}
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2007 Nokia Corporation. All rights reserved.
* Contact: Rémi Denis-Courmont
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Rémi Denis-Courmont, Nokia
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include "stun/bind.h"
#include "stun/stun-msg.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <netinet/in.h>
#undef NDEBUG /* ensure assertions are built-in */
#include <assert.h>
int main (void)
{
struct sockaddr_in ip4;
stun_msg_t buf;
ssize_t val;
size_t len;
static const uint8_t req[] =
"\x00\x01" "\x00\x00"
"\x00\x01\x02\x03\x04\x05\x06\x07"
"\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
memset (&ip4, 0, sizeof (ip4));
ip4.sin_family = AF_INET;
#ifdef HAVE_SA_LEN
ip4.sin_len = sizeof (addr);
#endif
ip4.sin_port = htons (12345);
ip4.sin_addr.s_addr = htonl (0x7f000001);
/* Same with too small response buffer */
stun_init_request (buf, STUN_BINDING);
len = sizeof (buf);
stun_finish (buf, &len);
len = 20 + 12 + 4 + stun_align (strlen (PACKAGE_STRING)) + 7;
val = stun_bind_reply (buf, &len, buf,
(struct sockaddr *)&ip4, sizeof (ip4), false);
assert (val == ENOBUFS);
assert (len == 0);
/* Same with too small response buffer */
stun_init_request (buf, STUN_BINDING);
stun_append_string (buf, sizeof (buf), 0x666, "Unknown attribute!");
len = sizeof (buf);
stun_finish (buf, &len);
len = 20 + 4 + stun_align (strlen (PACKAGE_STRING)) + 7;
val = stun_bind_reply (buf, &len, buf,
(struct sockaddr *)&ip4, sizeof (ip4), false);
assert (val == ENOBUFS);
assert (len == 0);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment