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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
|
/* SPDX-FileCopyrightText: 2019-2023 Greenbone AG
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "cpeutils.c"
#include <cgreen/cgreen.h>
#include <cgreen/mocks.h>
Describe (cpeutils);
BeforeEach (cpeutils)
{
}
AfterEach (cpeutils)
{
}
/* parse_entity */
Ensure (cpeutils, uri_cpe_to_cpe_struct)
{
cpe_struct_t cpe;
char *uri_cpe;
uri_cpe = "cpe:/a:microsoft:internet_explorer:8.0.6001:beta";
cpe_struct_init (&cpe);
uri_cpe_to_cpe_struct (uri_cpe, &cpe);
assert_that (cpe.part, is_equal_to_string ("a"));
assert_that (cpe.vendor, is_equal_to_string ("microsoft"));
assert_that (cpe.product, is_equal_to_string ("internet_explorer"));
assert_that (cpe.version, is_equal_to_string ("8\\.0\\.6001"));
assert_that (cpe.update, is_equal_to_string ("beta"));
assert_that (cpe.edition, is_equal_to_string ("ANY"));
assert_that (cpe.language, is_equal_to_string ("ANY"));
cpe_struct_free (&cpe);
uri_cpe = "cpe:/a:microsoft:internet_explorer:8.%2a:sp%3f";
cpe_struct_init (&cpe);
uri_cpe_to_cpe_struct (uri_cpe, &cpe);
assert_that (cpe.part, is_equal_to_string ("a"));
assert_that (cpe.vendor, is_equal_to_string ("microsoft"));
assert_that (cpe.product, is_equal_to_string ("internet_explorer"));
assert_that (cpe.version, is_equal_to_string ("8\\.\\*"));
assert_that (cpe.update, is_equal_to_string ("sp\\?"));
assert_that (cpe.edition, is_equal_to_string ("ANY"));
assert_that (cpe.language, is_equal_to_string ("ANY"));
cpe_struct_free (&cpe);
uri_cpe = "cpe:/a:hp:insight_diagnostics:7.4.0.1570::~~online~win2003~x64~";
cpe_struct_init (&cpe);
uri_cpe_to_cpe_struct (uri_cpe, &cpe);
assert_that (cpe.part, is_equal_to_string ("a"));
assert_that (cpe.vendor, is_equal_to_string ("hp"));
assert_that (cpe.product, is_equal_to_string ("insight_diagnostics"));
assert_that (cpe.version, is_equal_to_string ("7\\.4\\.0\\.1570"));
assert_that (cpe.update, is_equal_to_string ("ANY"));
assert_that (cpe.edition, is_equal_to_string ("ANY"));
assert_that (cpe.sw_edition, is_equal_to_string ("online"));
assert_that (cpe.target_sw, is_equal_to_string ("win2003"));
assert_that (cpe.target_hw, is_equal_to_string ("x64"));
assert_that (cpe.other, is_equal_to_string ("ANY"));
assert_that (cpe.language, is_equal_to_string ("ANY"));
cpe_struct_free (&cpe);
uri_cpe =
"cpe:/a:hp:insight_diagnostics:7.4.0.1570::~~online~win2003~x64~other";
cpe_struct_init (&cpe);
uri_cpe_to_cpe_struct (uri_cpe, &cpe);
assert_that (cpe.part, is_equal_to_string ("a"));
assert_that (cpe.vendor, is_equal_to_string ("hp"));
assert_that (cpe.product, is_equal_to_string ("insight_diagnostics"));
assert_that (cpe.version, is_equal_to_string ("7\\.4\\.0\\.1570"));
assert_that (cpe.update, is_equal_to_string ("ANY"));
assert_that (cpe.edition, is_equal_to_string ("ANY"));
assert_that (cpe.sw_edition, is_equal_to_string ("online"));
assert_that (cpe.target_sw, is_equal_to_string ("win2003"));
assert_that (cpe.target_hw, is_equal_to_string ("x64"));
assert_that (cpe.other, is_equal_to_string ("other"));
assert_that (cpe.language, is_equal_to_string ("ANY"));
cpe_struct_free (&cpe);
uri_cpe =
"cpe:/"
"a:hp:insight_diagnostics:7.4.0.1570::~~online~win2003~x64~other:english";
cpe_struct_init (&cpe);
uri_cpe_to_cpe_struct (uri_cpe, &cpe);
assert_that (cpe.part, is_equal_to_string ("a"));
assert_that (cpe.vendor, is_equal_to_string ("hp"));
assert_that (cpe.product, is_equal_to_string ("insight_diagnostics"));
assert_that (cpe.version, is_equal_to_string ("7\\.4\\.0\\.1570"));
assert_that (cpe.update, is_equal_to_string ("ANY"));
assert_that (cpe.edition, is_equal_to_string ("ANY"));
assert_that (cpe.sw_edition, is_equal_to_string ("online"));
assert_that (cpe.target_sw, is_equal_to_string ("win2003"));
assert_that (cpe.target_hw, is_equal_to_string ("x64"));
assert_that (cpe.other, is_equal_to_string ("other"));
assert_that (cpe.language, is_equal_to_string ("english"));
cpe_struct_free (&cpe);
uri_cpe = "This is a ~:SIGNAL:~ test.";
cpe_struct_init (&cpe);
uri_cpe_to_cpe_struct (uri_cpe, &cpe);
cpe_struct_free (&cpe);
}
Ensure (cpeutils, fs_cpe_to_cpe_struct)
{
cpe_struct_t cpe;
char *fs_cpe;
fs_cpe = "cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*";
cpe_struct_init (&cpe);
fs_cpe_to_cpe_struct (fs_cpe, &cpe);
assert_that (cpe.part, is_equal_to_string ("a"));
assert_that (cpe.vendor, is_equal_to_string ("microsoft"));
assert_that (cpe.product, is_equal_to_string ("internet_explorer"));
assert_that (cpe.version, is_equal_to_string ("8\\.0\\.6001"));
assert_that (cpe.update, is_equal_to_string ("beta"));
assert_that (cpe.edition, is_equal_to_string ("ANY"));
assert_that (cpe.language, is_equal_to_string ("ANY"));
assert_that (cpe.sw_edition, is_equal_to_string ("ANY"));
assert_that (cpe.target_sw, is_equal_to_string ("ANY"));
assert_that (cpe.target_hw, is_equal_to_string ("ANY"));
assert_that (cpe.other, is_equal_to_string ("ANY"));
cpe_struct_free (&cpe);
fs_cpe = "This is a ~:SIGNAL:~ test.";
cpe_struct_init (&cpe);
fs_cpe_to_cpe_struct (fs_cpe, &cpe);
cpe_struct_free (&cpe);
}
Ensure (cpeutils, cpe_struct_to_uri_cpe)
{
cpe_struct_t cpe;
char *uri_cpe;
cpe_struct_init (&cpe);
cpe.part = "a";
cpe.vendor = "microsoft";
cpe.product = "internet_explorer";
cpe.version = "8\\.0\\.6001";
cpe.update = "beta";
cpe.edition = "ANY";
uri_cpe = cpe_struct_to_uri_cpe (&cpe);
assert_that (uri_cpe, is_equal_to_string (
"cpe:/a:microsoft:internet_explorer:8.0.6001:beta"));
g_free (uri_cpe);
}
Ensure (cpeutils, cpe_struct_to_fs_cpe)
{
cpe_struct_t cpe;
char *fs_cpe;
cpe_struct_init (&cpe);
cpe.part = "a";
cpe.vendor = "microsoft";
cpe.product = "internet_explorer";
cpe.version = "8\\.0\\.6001";
cpe.update = "beta";
cpe.edition = "ANY";
fs_cpe = cpe_struct_to_fs_cpe (&cpe);
assert_that (
fs_cpe,
is_equal_to_string (
"cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*"));
g_free (fs_cpe);
}
Ensure (cpeutils, uri_cpe_to_fs_cpe)
{
char *uri_cpe = "cpe:/a:microsoft:internet_explorer:8.0.6001:beta";
char *fs_cpe = uri_cpe_to_fs_cpe (uri_cpe);
assert_that (
fs_cpe,
is_equal_to_string (
"cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*"));
g_free (fs_cpe);
uri_cpe = "cpe:/a:hp:insight_diagnostics:7.4.0.1570:-:~~online~win2003~x64~";
fs_cpe = uri_cpe_to_fs_cpe (uri_cpe);
assert_that (fs_cpe,
is_equal_to_string ("cpe:2.3:a:hp:insight_diagnostics:7.4.0."
"1570:-:*:*:online:win2003:x64:*"));
g_free (fs_cpe);
uri_cpe = "This is a ~:SIGNAL:~ test.";
fs_cpe = uri_cpe_to_fs_cpe (uri_cpe);
g_free (fs_cpe);
}
Ensure (cpeutils, fs_cpe_to_uri_cpe)
{
char *fs_cpe =
"cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*";
char *uri_cpe = fs_cpe_to_uri_cpe (fs_cpe);
assert_that (uri_cpe, is_equal_to_string (
"cpe:/a:microsoft:internet_explorer:8.0.6001:beta"));
g_free (uri_cpe);
fs_cpe =
"cpe:2.3:a:hp:insight_diagnostics:7.4.0.1570:-:*:*:online:win2003:x64:*";
uri_cpe = fs_cpe_to_uri_cpe (fs_cpe);
assert_that (
uri_cpe,
is_equal_to_string (
"cpe:/a:hp:insight_diagnostics:7.4.0.1570:-:~~online~win2003~x64~"));
g_free (uri_cpe);
fs_cpe =
"cpe:2.3:a:hp:insight_diagnostics:7\\:4.0.1570:-:*:*:online:win2003:x64:*";
uri_cpe = fs_cpe_to_uri_cpe (fs_cpe);
assert_that (
uri_cpe,
is_equal_to_string (
"cpe:/a:hp:insight_diagnostics:7%3A4.0.1570:-:~~online~win2003~x64~"));
g_free (uri_cpe);
fs_cpe =
"cpe:2.3:a:hp:insight_diagnostics:7.4.0.1570:-:*:*:online:win\\:2003:x64:*";
uri_cpe = fs_cpe_to_uri_cpe (fs_cpe);
assert_that (
uri_cpe,
is_equal_to_string (
"cpe:/a:hp:insight_diagnostics:7.4.0.1570:-:~~online~win%3A2003~x64~"));
g_free (uri_cpe);
fs_cpe = "cpe:2.3:a:hp:insight_diagnostics:7.4.0.1570:-:*:*:online:win\\:\\:"
"2003:x64:*";
uri_cpe = fs_cpe_to_uri_cpe (fs_cpe);
assert_that (
uri_cpe,
is_equal_to_string (
"cpe:/"
"a:hp:insight_diagnostics:7.4.0.1570:-:~~online~win%3A%3A2003~x64~"));
g_free (uri_cpe);
fs_cpe = "cpe:2.3:a:hp:insight_diagnostics:7.4.0.1570:-:*:*:online:"
"win2003\\\\:x64:*";
uri_cpe = fs_cpe_to_uri_cpe (fs_cpe);
assert_that (
uri_cpe,
is_equal_to_string (
"cpe:/a:hp:insight_diagnostics:7.4.0.1570:-:~~online~win2003%5C~x64~"));
g_free (uri_cpe);
fs_cpe = "This is a ~:SIGNAL:~ test.";
uri_cpe = fs_cpe_to_uri_cpe (fs_cpe);
g_free (uri_cpe);
}
Ensure (cpeutils, cpe_struct_match)
{
cpe_struct_t cpe1, cpe2;
char *fs_cpe1, *fs_cpe2;
fs_cpe1 = "cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*";
cpe_struct_init (&cpe1);
fs_cpe_to_cpe_struct (fs_cpe1, &cpe1);
assert_that (cpe_struct_match (&cpe1, &cpe1), is_equal_to (TRUE));
fs_cpe2 = "cpe:2.3:a:microsoft:internet_explorer:*:beta:*:*:*:*:*:*";
cpe_struct_init (&cpe2);
fs_cpe_to_cpe_struct (fs_cpe2, &cpe2);
assert_that (cpe_struct_match (&cpe2, &cpe1), is_equal_to (TRUE));
assert_that (cpe_struct_match (&cpe1, &cpe2), is_equal_to (FALSE));
fs_cpe2 = "cpe:2.3:a:microsoft:internet_explorer:*:-:*:*:*:*:*:*";
cpe_struct_free (&cpe2);
cpe_struct_init (&cpe2);
fs_cpe_to_cpe_struct (fs_cpe2, &cpe2);
assert_that (cpe_struct_match (&cpe2, &cpe1), is_equal_to (FALSE));
cpe_struct_free (&cpe1);
cpe_struct_free (&cpe2);
}
Ensure (cpeutils, uri_cpe_to_uri_product)
{
const char *uri_cpe;
gchar *uri_product;
uri_cpe = "cpe:/a:hp:insight_diagnostics:7.4.0.1570:-:~~online~win2003~x64~";
uri_product = uri_cpe_to_uri_product (uri_cpe);
assert_string_equal (uri_product, "cpe:/a:hp:insight_diagnostics");
g_free (uri_product);
}
/* Test suite. */
int
main (int argc, char **argv)
{
int ret;
TestSuite *suite;
suite = create_test_suite ();
add_test_with_context (suite, cpeutils, uri_cpe_to_cpe_struct);
add_test_with_context (suite, cpeutils, fs_cpe_to_cpe_struct);
add_test_with_context (suite, cpeutils, cpe_struct_to_uri_cpe);
add_test_with_context (suite, cpeutils, cpe_struct_to_fs_cpe);
add_test_with_context (suite, cpeutils, uri_cpe_to_fs_cpe);
add_test_with_context (suite, cpeutils, fs_cpe_to_uri_cpe);
add_test_with_context (suite, cpeutils, cpe_struct_match);
add_test_with_context (suite, cpeutils, uri_cpe_to_uri_product);
if (argc > 1)
ret = run_single_test (suite, argv[1], create_text_reporter ());
else
ret = run_test_suite (suite, create_text_reporter ());
destroy_test_suite (suite);
return ret;
}
|