File: test_strispassword_s.c

package info (click to toggle)
safeclib 3.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,748 kB
  • sloc: ansic: 48,732; sh: 4,842; makefile: 1,228; perl: 374
file content (107 lines) | stat: -rw-r--r-- 2,315 bytes parent folder | download
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*------------------------------------------------------------------
 * test_strispassword_s
 * File 'extstr/strispassword_s.c'
 * Lines executed:97.44% of 39
 *
 *------------------------------------------------------------------
 */

#include "test_private.h"
#include "safe_str_lib.h"

#define LEN 64

int main(void) {
    bool rc;
    uint32_t len;
    char str[LEN];
    int errs = 0;

    /*--------------------------------------------------*/

#ifndef HAVE_CT_BOS_OVR
    EXPECT_BOS("empty dest")
    rc = strispassword_s(NULL, LEN);
    ERR(false)

    EXPECT_BOS("empty dest or dmax")
    rc = strispassword_s("Test4You&", 0);
    ERR(false)

    strcpy(str, "Test4You&");
    EXPECT_BOS("dest overflow")
    rc = strispassword_s(str, 999);
    ERR(false)

    EXPECT_BOS("dest overflow")
    rc = strispassword_s("Test4You&", 999);
    ERR(false)

    EXPECT_BOS("dest overflow")
    rc = strispassword_s("", 9);
    ERR(false)

    EXPECT_BOS("dest overflow")
    rc = strispassword_s("", LEN);
    ERR(false)
#endif

    /*--------------------------------------------------*/

    strcpy(str, "Test4You*123");
    len = 8;

    rc = strispassword_s(str, len);
    ERR(false)
    /*--------------------------------------------------*/

    strcpy(str, "Test4You*");
    len = strlen(str);

    rc = strispassword_s(str, len);
    ERR(true)
    /*--------------------------------------------------*/

    strcpy(str, "Test4You*Test4You*Test4You*");
    len = strlen(str);

    rc = strispassword_s(str, len);
    ERR(true)
    /*--------------------------------------------------*/

    strcpy(str, "Eest!22/");
    len = strlen(str);

    rc = strispassword_s(str, len);
    ERR(false)
    /*--------------------------------------------------*/

    strcpy(str, "pa$$W0rD");
    len = strlen(str);

    rc = strispassword_s(str, len);
    ERR(true)

    strcpy(str, "<a]$b}0X_D");
    len = strlen(str);

    rc = strispassword_s(str, len);
    ERR(true)

    /*--------------------------------------------------*/

    strcpy(str, "pa$$W0rD f");
    len = strlen(str);

    rc = strispassword_s(str, len);
    ERR(false)

    strcpy(str, "Test");
    len = strlen(str);

    rc = strispassword_s(str, len);
    ERR(false)
    /*--------------------------------------------------*/

    return (errs);
}