TODO: OTP-authenticatd password change tested
[libisds.git] / test / offline / soap-string2isds_otp_resolution.c
blobe846a2fe73c7a94c6e18ce5670536dbd0a51f6f4
1 #include "../test.h"
2 #include "soap.c"
4 static int test_string2isds_otp_resolution(const char *string,
5 const isds_otp_resolution correct_resolution) {
6 isds_otp_resolution new_resolution;
8 new_resolution = string2isds_otp_resolution(string);
9 if (new_resolution != correct_resolution)
10 FAIL_TEST("string2isds_otp_resolution() returned unexpected value: "
11 "expected=%d got=%d", correct_resolution, new_resolution);
12 PASS_TEST;
15 int main(int argc, char **argv) {
16 int i;
18 const char *hotp_strings[] = {
19 "authentication.error.userIsNotAuthenticated",
20 "authentication.error.intruderDetected",
21 "authentication.error.paswordExpired",
22 "authentication.error.badRole"
24 const isds_otp_resolution hotp_resolutions[] = {
25 OTP_RESOLUTION_BAD_AUTHENTICATION,
26 OTP_RESOLUTION_ACCESS_BLOCKED,
27 OTP_RESOLUTION_PASSWORD_EXPIRED,
28 OTP_RESOLUTION_UNAUTHORIZED
31 const char *totp_strings[] = {
32 "authentication.info.totpSended",
33 "authentication.error.userIsNotAuthenticated",
34 "authentication.error.intruderDetected",
35 "authentication.error.paswordExpired",
36 "authentication.info.cannotSendQuickly",
37 "authentication.error.badRole",
38 "authentication.info.totpNotSended"
40 const isds_otp_resolution totp_resolutions[] = {
41 OTP_RESOLUTION_TOTP_SENT,
42 OTP_RESOLUTION_BAD_AUTHENTICATION,
43 OTP_RESOLUTION_ACCESS_BLOCKED,
44 OTP_RESOLUTION_PASSWORD_EXPIRED,
45 OTP_RESOLUTION_TO_FAST,
46 OTP_RESOLUTION_UNAUTHORIZED,
47 OTP_RESOLUTION_TOTP_NOT_SENT
50 INIT_TEST("OTP X-Response-message-Code string to isds_otp_resolution "
51 "conversion");
53 /* HOTP */
54 for (i = 0; i < sizeof(hotp_strings)/sizeof(hotp_strings[0]); i++) {
55 TEST(hotp_strings[i], test_string2isds_otp_resolution,
56 hotp_strings[i], hotp_resolutions[i]);
59 /* TOTP */
60 for (i = 0; i < sizeof(totp_strings)/sizeof(totp_strings[0]); i++) {
61 TEST(totp_strings[i], test_string2isds_otp_resolution,
62 totp_strings[i], totp_resolutions[i]);
65 /* Corner cases */
66 TEST("Unknown value", test_string2isds_otp_resolution, "X-Unknown value",
67 OTP_RESOLUTION_UNKNOWN);
68 TEST("Empty string", test_string2isds_otp_resolution, "",
69 OTP_RESOLUTION_UNKNOWN);
70 TEST("NULL pointer", test_string2isds_otp_resolution, NULL,
71 OTP_RESOLUTION_UNKNOWN);
73 SUM_TEST();