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
|
/*
*
* Visual Voicemail Daemon
*
* Copyright (C) 2022, Chris Talbot <chris@talbothome.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <glib.h>
#include <glib/gprintf.h>
#include "resolve.h"
#include "vvmutil.h"
#include "vvm3-activation.h"
#define SPGURL_TO_TEST_ONE "https://spg.vzw.com/newSelfProvisioning/SelfProvisioning"
#define BUTTONURL_TO_TEST_ONE "https://spg.vzw.com/newSelfProvisioning/bvvmprovision?sfo=XXXXX"
static const char FIRST_REQUEST_0[] = "./unit/vvm3_activation/first request.xml";
static const char SECOND_REQUEST_0[] = "./unit/vvm3_activation/second request.html";
static const char SECOND_REQUEST_1[] = "./unit/vvm3_activation/second request 1.html";
// Valid URLs
static const char url_0[] = "https://spg.vzw.com/newSelfProvisioning/SelfProvisioning";
static const char url_1[] = "https://spg.vzw.com:443/newSelfProvisioning/bvvmdecline";
static const char url_2[] = "http://spg.vzw.com/newSelfProvisioning/SelfProvisioning";
static const char url_3[] = "http://spg.vzw.com:443/newSelfProvisioning/bvvmdecline";
static const char url_4[] = "http://spg.dsfsdf.dgssfdds.vzw.com/newSelfProvisioning/SelfProvisioning";
static const char url_5[] = "http://spgrrfbnjt.ssxvcr.45td.vzw.com:443/newSelfProvisioning/bvvmdecline";
// Invalid Domain
static const char url_6[] = "http://spg.not_vzw.com/newSelfProvisioning/SelfProvisioning";
static const char url_7[] = "http://spg.not_vzw.com:443/newSelfProvisioning/bvvmdecline";
// Not http:// or https://
static const char url_8[] = "ftp://spg.vzw.com:443/newSelfProvisioning/bvvmdecline";
static const char url_9[] = "spg.vzw.com:443/newSelfProvisioning/bvvmdecline";
// Valid URL, Activate URL
static const char url_10[] = "https://vmg.vzw.com/VMGIMS/VMServices";
// Put .vzw.com not in domain
static const char url_11[] = "http://spg.example.com/.vzw.com/newSelfProvisioning/SelfProvisioning";
static const char url_12[] = "http://spg.example.com/.vzw.com:443/newSelfProvisioning/SelfProvisioning";
// .vzw.com is a subdommain, not root domain
static const char url_13[] = "https://vmg.vzw.com.example.com/VMGIMS/VMServices";
static void
append_file_to_g_string (const char *file_to_copy,
GString *data_to_parse)
{
unsigned int len;
struct stat st;
unsigned char *pdu;
int fd;
fd = open (file_to_copy, O_RDONLY);
if (fd < 0)
{
g_printerr ("Failed to open path %s\n", file_to_copy);
goto out;
}
if (fstat (fd, &st) < 0)
{
g_printerr ("Failed to stat %s\n", file_to_copy);
close (fd);
goto out;
}
len = st.st_size;
pdu = mmap (NULL, len, PROT_READ, MAP_SHARED, fd, 0);
if (!pdu || pdu == MAP_FAILED)
{
g_printerr ("Failed to mmap %s\n", file_to_copy);
close (fd);
goto out;
}
data_to_parse = g_string_append (data_to_parse, (char *) pdu);
munmap (pdu, len);
close (fd);
return;
out:
g_assert (FALSE);
return;
}
static void
test_vvm3 (gconstpointer data)
{
g_autofree char *buttonUrl = NULL;
g_autofree char *spgUrl = NULL;
GString *data_to_parse;
data_to_parse = g_string_new (NULL);
append_file_to_g_string (FIRST_REQUEST_0, data_to_parse);
spgUrl = vvm3_xml_find_spgUrl (data_to_parse);
if (g_strcmp0 (spgUrl, SPGURL_TO_TEST_ONE) != 0)
g_printerr ("Captured URL id %s not the same as original %s\n", spgUrl, SPGURL_TO_TEST_ONE);
g_assert (g_strcmp0 (spgUrl, SPGURL_TO_TEST_ONE) == 0);
g_string_free (data_to_parse, TRUE);
data_to_parse = g_string_new (NULL);
append_file_to_g_string (SECOND_REQUEST_0, data_to_parse);
buttonUrl = vvm3_html_find_buttonUrl (data_to_parse);
if (g_strcmp0 (buttonUrl, BUTTONURL_TO_TEST_ONE) != 0)
g_printerr ("Captured URL id %s not the same as original %s\n", buttonUrl, BUTTONURL_TO_TEST_ONE);
g_assert (g_strcmp0 (buttonUrl, BUTTONURL_TO_TEST_ONE) == 0);
g_string_free (data_to_parse, TRUE);
data_to_parse = g_string_new (NULL);
append_file_to_g_string (SECOND_REQUEST_1, data_to_parse);
buttonUrl = vvm3_html_find_buttonUrl (data_to_parse);
if (g_strcmp0 (buttonUrl, BUTTONURL_TO_TEST_ONE) != 0)
g_printerr ("Captured URL id %s not the same as original %s\n", buttonUrl, BUTTONURL_TO_TEST_ONE);
g_assert (g_strcmp0 (buttonUrl, BUTTONURL_TO_TEST_ONE) == 0);
g_string_free (data_to_parse, TRUE);
g_assert (validate_vvm3_host (SPGURL_TO_TEST_ONE));
g_assert (validate_vvm3_host (BUTTONURL_TO_TEST_ONE));
g_assert (validate_vvm3_host (url_0));
g_assert (validate_vvm3_host (url_1));
g_assert (validate_vvm3_host (url_2));
g_assert (validate_vvm3_host (url_3));
g_assert (validate_vvm3_host (url_4));
g_assert (validate_vvm3_host (url_5));
g_assert (!validate_vvm3_host (url_6));
g_assert (!validate_vvm3_host (url_7));
g_assert (!validate_vvm3_host (url_8));
g_assert (!validate_vvm3_host (url_9));
g_assert (validate_vvm3_host (url_10));
g_assert (!validate_vvm3_host (url_11));
g_assert (!validate_vvm3_host (url_12));
g_assert (!validate_vvm3_host (url_13));
return;
}
int
main (int argc,
char **argv)
{
g_test_init (&argc, &argv, NULL);
g_test_add_data_func ("/vvmutil/vvm3 Activation Test",
NULL, test_vvm3);
return g_test_run ();
}
|