File: load_raw.c

package info (click to toggle)
libisds 0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,348 kB
  • ctags: 1,659
  • sloc: ansic: 24,898; sh: 11,772; makefile: 393; xml: 375; sed: 16
file content (181 lines) | stat: -rw-r--r-- 5,293 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include "../test.h"
#include "crypto.h"
#include <string.h>


struct test {
    char *name;
    char *file;
    isds_raw_type type;
    _Bool should_pass;
};
    

static int test_load_message(struct isds_ctx *context,
        const struct test *test) {
    isds_error err;
    int fd;
    void *buffer = NULL;
    size_t length = 0;
    struct isds_message *message = NULL;

    if (!test) return 1;

    if (test_mmap_file(test->file, &fd, &buffer, &length))
        FAIL_TEST("Could not load test data from `%s' file", test->file);

    if (!test->should_pass)
        /* Do not log expected XML parser failures */
        isds_set_logging(ILF_XML, ILL_NONE);
    else
        isds_set_logging(ILF_ALL, ILL_WARNING);

    err = isds_load_message(context, test->type, buffer, length,
            &message, BUFFER_DONT_STORE);
    isds_message_free(&message);
    test_munmap_file(fd, buffer, length);

    if (test->should_pass) {
        if (err)
            FAIL_TEST("Message loading should succeded: got=%s",
                    isds_strerror(err));
    } else {
        if (!err)
            FAIL_TEST("Message loading should fail: got=%s",
                    isds_strerror(err));
    }

    PASS_TEST;
}


static int test_load_delivery(struct isds_ctx *context,
        const struct test *test) {
    isds_error err;
    int fd;
    void *buffer = NULL;
    size_t length = 0;
    struct isds_message *message = NULL;

    if (!test) return 1;

    if (test_mmap_file(test->file, &fd, &buffer, &length))
        FAIL_TEST("Could not load test data from `%s' file", test->file);

    err = isds_load_delivery_info(context, test->type, buffer, length,
            &message, BUFFER_DONT_STORE);
    isds_message_free(&message);
    test_munmap_file(fd, buffer, length);

    if (test->should_pass) {
        if (err)
            FAIL_TEST("Message loading should succeded: got=%s",
                    isds_strerror(err));
    } else {
        if (!err)
            FAIL_TEST("Message loading should fail: got=%s",
                    isds_strerror(err));
    }

    PASS_TEST;
}


int main(int argc, char **argv) {
    struct test messages[] = {
        {
            .name = "unsigned incoming message",
            .file = SRCDIR "/server/messages/received_message-151916.xml",
            .type = RAWTYPE_INCOMING_MESSAGE,
            .should_pass = 1
        },
        {
            .name = "plain signed incoming message",
            .file = SRCDIR
                "/server/messages/received_signed_message-330141.xml",
            .type = RAWTYPE_PLAIN_SIGNED_INCOMING_MESSAGE,
            .should_pass = 1
        },
        {
            .name = "CMS signed incoming message",
            .file = SRCDIR "/server/messages/received_message-330141.zfo",
            .type = RAWTYPE_CMS_SIGNED_INCOMING_MESSAGE,
            .should_pass = 1
        },
        {
            .name = "plain signed sent message",
            .file = SRCDIR "/server/messages/sent_message-206720.xml",
            .type = RAWTYPE_PLAIN_SIGNED_OUTGOING_MESSAGE,
            .should_pass = 1
        },
        {
            .name = "CMS signed sent message",
            .file = SRCDIR "/server/messages/signed_sent_message-151874.zfo",
            .type = RAWTYPE_CMS_SIGNED_OUTGOING_MESSAGE,
            .should_pass = 1
        },
        {
            .name = "plain signed sent message with XML documents",
            .file = SRCDIR "/server/messages/signed_sent_xml_message-376701.xml",
            .type = RAWTYPE_PLAIN_SIGNED_OUTGOING_MESSAGE,
            .should_pass = 1
        },
        {
            .name = "text file is not an incoming message",
            .file = "Makefile",
            .type = RAWTYPE_INCOMING_MESSAGE,
            .should_pass = 0
        },
        {
            .name = NULL
        }
    };

    struct test deliveries[] = {
        {
            .name = "unsigned delivery info",
            .file = SRCDIR "/server/messages/delivery_info-316590.xml",
            .type = RAWTYPE_DELIVERYINFO,
            .should_pass = 1
        },
        {
            .name = "plain signed delivery info",
            .file = SRCDIR "/server/messages/signed_delivered-DD_170272.xml",
            .type = RAWTYPE_PLAIN_SIGNED_DELIVERYINFO,
            .should_pass = 1
        },
        {
            .name = "CMS signed delivery info",
            .file = SRCDIR "/server/messages/signed_delivered-DD_170272.zfo",
            .type = RAWTYPE_CMS_SIGNED_DELIVERYINFO,
            .should_pass = 1
        },
        {
            .name = "text file is not a delivery info",
            .file = "Makefile",
            .type = RAWTYPE_INCOMING_MESSAGE,
            .should_pass = 0
        },
        {
            .name = NULL
        }
    };
    struct isds_ctx *context = NULL;

    INIT_TEST("load_raw");

    if (isds_init())
        ABORT_UNIT("init_isds() failed");

    context = isds_ctx_create();
    if (!context)
        ABORT_UNIT("isds_ctx_create() failed");
   
    for (int i = 0; messages[i].name; i++) 
        TEST(messages[i].name, test_load_message, context, &messages[i]);
    for (int i = 0; deliveries[i].name; i++) 
        TEST(deliveries[i].name, test_load_delivery, context, &deliveries[i]);

    isds_ctx_free(&context);
    SUM_TEST();
}