add test for new API's
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
committed by
Dmitry Podgorny
parent
27be6acaeb
commit
25d3a2d459
1
.gitignore
vendored
1
.gitignore
vendored
@@ -61,6 +61,7 @@ tests/test_snprintf
|
||||
tests/test_sock
|
||||
tests/test_stanza
|
||||
tests/test_string
|
||||
tests/test_xmppaddr
|
||||
m4/
|
||||
libstrophe.project
|
||||
libs/
|
||||
|
||||
@@ -165,6 +165,10 @@ TESTS = \
|
||||
tests/test_stanza \
|
||||
tests/test_resolver
|
||||
|
||||
if !DISABLE_TLS
|
||||
TESTS += tests/test_xmppaddr
|
||||
endif
|
||||
|
||||
check_PROGRAMS = $(TESTS)
|
||||
|
||||
tests_check_parser_SOURCES = tests/check_parser.c tests/test.h
|
||||
@@ -230,6 +234,11 @@ tests_test_stanza_CFLAGS = $(STROPHE_FLAGS)
|
||||
tests_test_stanza_LDADD = $(STROPHE_LIBS)
|
||||
tests_test_stanza_LDFLAGS = -static
|
||||
|
||||
tests_test_xmppaddr_SOURCES = tests/test_xmppaddr.c
|
||||
tests_test_xmppaddr_CFLAGS = $(STROPHE_FLAGS) -I$(top_srcdir)/src
|
||||
tests_test_xmppaddr_LDADD = $(STROPHE_LIBS)
|
||||
tests_test_xmppaddr_LDFLAGS = -static
|
||||
|
||||
format:
|
||||
@echo " * run clang-format on all sources"
|
||||
@dos2unix -q src/*.[ch] *.h tests/*.[ch] examples/*.c
|
||||
|
||||
16
tests/cert.pem
Normal file
16
tests/cert.pem
Normal file
@@ -0,0 +1,16 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICfjCCAjSgAwIBAgIIW5u5Vwn2Mv0wCgYIKoZIzj0EAwIwSzFJMEcGA1UEAwxA
|
||||
dmVyeS5sb25nLnVzZXJuYW1lQHNvLnRoZS5hc24xLmxlbmd0aC5pcy5hLnZhbGlk
|
||||
LmFzY2lpLmNoYXJhY3RlcjAgFw0yMTAzMDExOTExMDBaGA8yMTIxMDMwMTE5MTEw
|
||||
MFowSzFJMEcGA1UEAwxAdmVyeS5sb25nLnVzZXJuYW1lQHNvLnRoZS5hc24xLmxl
|
||||
bmd0aC5pcy5hLnZhbGlkLmFzY2lpLmNoYXJhY3RlcjBJMBMGByqGSM49AgEGCCqG
|
||||
SM49AwEBAzIABI/tSR5cZ9iHCVw0JwmKLvV3TbxPg3kDdouB0R2WKEdEWwXMIHkE
|
||||
85RReISg+9/JDaOCAQ4wggEKMAkGA1UdEwQCMAAwHQYDVR0OBBYEFPjLGyHxqlOV
|
||||
nXJQ9YBrnureO8LiMB8GA1UdIwQYMBaAFPjLGyHxqlOVnXJQ9YBrnureO8LiMAsG
|
||||
A1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDAjCBmgYDVR0RBIGSMIGPoE4G
|
||||
CCsGAQUFBwgFoEIMQHZlcnkubG9uZy51c2VybmFtZUBzby50aGUuYXNuMS5sZW5n
|
||||
dGguaXMuYS52YWxpZC5hc2NpaS5jaGFyYWN0ZXKBDnlldEBub3RoZXIuc2Fugg53
|
||||
d3cuc3Ryb3BoZS5pbaAdBggrBgEFBQcIBaARDA9zZWNvbmRAeG1wcC5qaWQwCgYI
|
||||
KoZIzj0EAwIDOAAwNQIZAJmfqBhBMdaKCiWEuXu84K4+lznfzlRfmwIYCGRD1xk0
|
||||
9cRa3V6PVwYWz6HcdRdMUBUj
|
||||
-----END CERTIFICATE-----
|
||||
5
tests/key.pem
Normal file
5
tests/key.pem
Normal file
@@ -0,0 +1,5 @@
|
||||
-----BEGIN EC PRIVATE KEY-----
|
||||
MF8CAQEEGF7SsbTSOjzb97nFc7Qbt4sic+1nZk+ETqAKBggqhkjOPQMBAaE0AzIA
|
||||
BI/tSR5cZ9iHCVw0JwmKLvV3TbxPg3kDdouB0R2WKEdEWwXMIHkE85RReISg+9/J
|
||||
DQ==
|
||||
-----END EC PRIVATE KEY-----
|
||||
68
tests/test_xmppaddr.c
Normal file
68
tests/test_xmppaddr.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/* test_xmppaddr.c
|
||||
** libstrophe XMPP client library -- test routines for the xmppaddr
|
||||
** certificate API's
|
||||
**
|
||||
** Copyright (C) 2021 Steffen Jaeckel
|
||||
**
|
||||
** This software is provided AS-IS with no warranty, either express
|
||||
** or implied.
|
||||
**
|
||||
** This program is dual licensed under the MIT and GPLv3 licenses.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "strophe.h"
|
||||
|
||||
#include "test.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
xmpp_ctx_t *ctx;
|
||||
xmpp_conn_t *conn;
|
||||
xmpp_log_t *log;
|
||||
|
||||
char xmppaddr_num[] = "0";
|
||||
unsigned int n;
|
||||
|
||||
xmpp_initialize();
|
||||
log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG);
|
||||
ctx = xmpp_ctx_new(NULL, log);
|
||||
conn = xmpp_conn_new(ctx);
|
||||
|
||||
xmpp_conn_set_client_cert(conn, "tests/cert.pem", "tests/key.pem");
|
||||
|
||||
xmppaddr_num[0] = xmppaddr_num[0] + xmpp_conn_cert_xmppaddr_num(conn);
|
||||
|
||||
COMPARE(xmppaddr_num, "2");
|
||||
|
||||
for (n = 0; n < 3; ++n) {
|
||||
char *r = xmpp_conn_cert_xmppaddr(conn, n);
|
||||
switch (n) {
|
||||
case 0:
|
||||
COMPARE(r, "very.long.username@so.the.asn1.length.is.a.valid.ascii."
|
||||
"character");
|
||||
break;
|
||||
case 1:
|
||||
COMPARE(r, "second@xmpp.jid");
|
||||
break;
|
||||
default:
|
||||
if (r != NULL) {
|
||||
printf("\nThere shall only be two id-on-xmppAddr SANs!\nFound "
|
||||
"another one: %s\n",
|
||||
r);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
free(r);
|
||||
}
|
||||
|
||||
xmpp_conn_release(conn);
|
||||
xmpp_ctx_free(ctx);
|
||||
xmpp_shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user