summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorMichael Brown2015-08-26 23:35:42 +0200
committerMichael Brown2015-09-02 14:38:53 +0200
commit53d2d9e3c37d6170341818a254e18d341ee15511 (patch)
tree53cd2b5a20c37d270e3046d4823e62d3337ca7c2 /src/tests
parent[pxe] Populate ciaddr in fake PXE Boot Server ACK packet (diff)
downloadipxe-53d2d9e3c37d6170341818a254e18d341ee15511.tar.gz
ipxe-53d2d9e3c37d6170341818a254e18d341ee15511.tar.xz
ipxe-53d2d9e3c37d6170341818a254e18d341ee15511.zip
[uri] Generalise tftp_uri() to pxe_uri()
Merge the functionality of parse_next_server_and_filename() and tftp_uri() into a single pxe_uri(), which takes a server address (IPv4/IPv6/none) and a filename, and produces a URI using the rule: - if the filename is a hierarchical absolute URI (i.e. includes a scheme such as "http://" or "tftp://") then use that URI and ignore the server address, - otherwise, if the server address is recognised (according to sa_family) then construct a TFTP URI based on the server address, port, and filename - otherwise fail. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/uri_test.c106
1 files changed, 77 insertions, 29 deletions
diff --git a/src/tests/uri_test.c b/src/tests/uri_test.c
index da7fb8ab..42c1c43d 100644
--- a/src/tests/uri_test.c
+++ b/src/tests/uri_test.c
@@ -35,6 +35,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <string.h>
#include <byteswap.h>
#include <ipxe/uri.h>
+#include <ipxe/tcpip.h>
#include <ipxe/params.h>
#include <ipxe/test.h>
@@ -66,12 +67,15 @@ struct uri_resolve_test {
const char *resolved;
};
-/** A TFTP URI test */
-struct uri_tftp_test {
- /** Next-server address */
- struct in_addr next_server;
- /** Port number */
- unsigned int port;
+/** A PXE URI test */
+struct uri_pxe_test {
+ /** Server address */
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in sin;
+ struct sockaddr_in6 sin6;
+ struct sockaddr_tcpip st;
+ } server;
/** Filename */
const char *filename;
/** URI */
@@ -323,20 +327,20 @@ static void uri_resolve_path_okx ( struct uri_resolve_test *test,
uri_resolve_path_okx ( test, __FILE__, __LINE__ )
/**
- * Report URI TFTP test result
+ * Report URI PXE test result
*
- * @v test URI TFTP test
+ * @v test URI PXE test
* @v file Test code file
* @v line Test code line
*/
-static void uri_tftp_okx ( struct uri_tftp_test *test, const char *file,
- unsigned int line ) {
+static void uri_pxe_okx ( struct uri_pxe_test *test, const char *file,
+ unsigned int line ) {
char buf[ strlen ( test->string ) + 1 /* NUL */ ];
struct uri *uri;
size_t len;
/* Construct URI */
- uri = tftp_uri ( test->next_server, test->port, test->filename );
+ uri = pxe_uri ( &test->server.sa, test->filename );
okx ( uri != NULL, file, line );
if ( uri ) {
uri_okx ( uri, &test->uri, file, line );
@@ -346,7 +350,7 @@ static void uri_tftp_okx ( struct uri_tftp_test *test, const char *file,
}
uri_put ( uri );
}
-#define uri_tftp_ok( test ) uri_tftp_okx ( test, __FILE__, __LINE__ )
+#define uri_pxe_ok( test ) uri_pxe_okx ( test, __FILE__, __LINE__ )
/**
* Report current working URI test result
@@ -678,9 +682,33 @@ static struct uri_resolve_test uri_fragment = {
"http://192.168.0.254/test#bar",
};
-/** TFTP URI with absolute path */
-static struct uri_tftp_test uri_tftp_absolute = {
- { .s_addr = htonl ( 0xc0a80002 ) /* 192.168.0.2 */ }, 0,
+/** PXE URI with absolute URI */
+static struct uri_pxe_test uri_pxe_absolute = {
+ {
+ /* 192.168.0.3 */
+ .sin = {
+ .sin_family = AF_INET,
+ .sin_addr = { .s_addr = htonl ( 0xc0a80003 ) },
+ },
+ },
+ "http://not.a.tftp/uri",
+ {
+ .scheme = "http",
+ .host = "not.a.tftp",
+ .path = "/uri",
+ },
+ "http://not.a.tftp/uri",
+};
+
+/** PXE URI with absolute path */
+static struct uri_pxe_test uri_pxe_absolute_path = {
+ {
+ /* 192.168.0.2 */
+ .sin = {
+ .sin_family = AF_INET,
+ .sin_addr = { .s_addr = htonl ( 0xc0a80002 ) },
+ },
+ },
"/absolute/path",
{
.scheme = "tftp",
@@ -690,9 +718,15 @@ static struct uri_tftp_test uri_tftp_absolute = {
"tftp://192.168.0.2/absolute/path",
};
-/** TFTP URI with relative path */
-static struct uri_tftp_test uri_tftp_relative = {
- { .s_addr = htonl ( 0xc0a80003 ) /* 192.168.0.3 */ }, 0,
+/** PXE URI with relative path */
+static struct uri_pxe_test uri_pxe_relative_path = {
+ {
+ /* 192.168.0.3 */
+ .sin = {
+ .sin_family = AF_INET,
+ .sin_addr = { .s_addr = htonl ( 0xc0a80003 ) },
+ },
+ },
"relative/path",
{
.scheme = "tftp",
@@ -702,9 +736,15 @@ static struct uri_tftp_test uri_tftp_relative = {
"tftp://192.168.0.3/relative/path",
};
-/** TFTP URI with path containing special characters */
-static struct uri_tftp_test uri_tftp_icky = {
- { .s_addr = htonl ( 0x0a000006 ) /* 10.0.0.6 */ }, 0,
+/** PXE URI with path containing special characters */
+static struct uri_pxe_test uri_pxe_icky = {
+ {
+ /* 10.0.0.6 */
+ .sin = {
+ .sin_family = AF_INET,
+ .sin_addr = { .s_addr = htonl ( 0x0a000006 ) },
+ },
+ },
"C:\\tftpboot\\icky#path",
{
.scheme = "tftp",
@@ -714,9 +754,16 @@ static struct uri_tftp_test uri_tftp_icky = {
"tftp://10.0.0.6/C%3A\\tftpboot\\icky%23path",
};
-/** TFTP URI with custom port */
-static struct uri_tftp_test uri_tftp_port = {
- { .s_addr = htonl ( 0xc0a80001 ) /* 192.168.0.1 */ }, 4069,
+/** PXE URI with custom port */
+static struct uri_pxe_test uri_pxe_port = {
+ {
+ /* 192.168.0.1:4069 */
+ .sin = {
+ .sin_family = AF_INET,
+ .sin_addr = { .s_addr = htonl ( 0xc0a80001 ) },
+ .sin_port = htons ( 4069 ),
+ },
+ },
"/another/path",
{
.scheme = "tftp",
@@ -857,11 +904,12 @@ static void uri_test_exec ( void ) {
uri_resolve_ok ( &uri_query );
uri_resolve_ok ( &uri_fragment );
- /* TFTP URI construction tests */
- uri_tftp_ok ( &uri_tftp_absolute );
- uri_tftp_ok ( &uri_tftp_relative );
- uri_tftp_ok ( &uri_tftp_icky );
- uri_tftp_ok ( &uri_tftp_port );
+ /* PXE URI construction tests */
+ uri_pxe_ok ( &uri_pxe_absolute );
+ uri_pxe_ok ( &uri_pxe_absolute_path );
+ uri_pxe_ok ( &uri_pxe_relative_path );
+ uri_pxe_ok ( &uri_pxe_icky );
+ uri_pxe_ok ( &uri_pxe_port );
/* Current working URI tests */
uri_churi_ok ( uri_churi );