<commit_before>/* Copyright (c) 2009-2014 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "net.h"
#include "http-url.h"
#include "test-common.h"

struct valid_http_url_test {
	const char *url;
	enum http_url_parse_flags flags;
	struct http_url url_base;

	struct http_url url_parsed;
};

/* Valid HTTP URL tests */
static struct valid_http_url_test valid_url_tests[] = {
	/* Generic tests */
	{
		.url = "http://localhost",
		.url_parsed = {
			.host_name = "localhost" }
	},{
		.url = "http://www.%65%78%61%6d%70%6c%65.com",
		.url_parsed = {
			.host_name = "www.example.com" }
	},{
		.url = "http://www.dovecot.org:8080",
		.url_parsed = {
			.host_name = "www.dovecot.org",
			.port = 8080, .have_port = TRUE }
	},{
		.url = "http://127.0.0.1",
		.url_parsed = {
			.host_name = "127.0.0.1",
			.have_host_ip = TRUE }
#ifdef HAVE_IPV6
	},{
		.url = "http://[::1]",
		.url_parsed = {
			.host_name = "[::1]",
			.have_host_ip = TRUE }
	},{
		.url = "http://[::1]:8080",
		.url_parsed = {
			.host_name = "[::1]",
			.have_host_ip = TRUE,
			.port = 8080, .have_port = TRUE }
#endif
	},{
		.url = "http://user@api.dovecot.org",
		.flags = HTTP_URL_ALLOW_USERINFO_PART,
		.url_parsed = {
			.host_name = "api.dovecot.org", .user = "user" }
	},{
		.url = "http://userid:secret@api.do<EMAIL>.<EMAIL>",
		.flags = HTTP_URL_ALLOW_USERINFO_PART,
		.url_parsed = {
			.host_name = "api.dovecot.org",
			.user = "userid", .password = "<PASSWORD>" }
	},{
		.url = "http://su%3auserid:<EMAIL>",
		.flags = HTTP_URL_ALLOW_USERINFO_PART,
		.url_parsed = {
			.host_name = "api.dovecot.org",
			.user = "su:userid", .password = "<PASSWORD>" }
	},{
		.url = "http://www.example.com/"
			"?question=What%20are%20you%20doing%3f&answer=Nothing.",
		.url_parsed = {
			.path = "/",
			.host_name = "www.example.com",
			.enc_query = "question=What%20are%20you%20doing%3f&answer=Nothing." }
	},{
		.url = "http://www.example.com/#Status%20of%20development",
		.flags = HTTP_URL_ALLOW_FRAGMENT_PART,
		.url_parsed = {
			.path = "/",
			.host_name = "www.example.com",
			.enc_fragment = "Status%20of%20development" }

	
	/* RFC 3986, Section 5.4. Reference Resolution Examples 
	 *
	 * Within a representation with a well defined base URI of
	 *
	 *  http://a/b/c/d;p?q
	 *
	 * a relative reference is transformed to its target URI as follows.
	 *
	 * 5.4.1. Normal Examples
	 */<commit_msg>lib-http: test-http-url - add some tricky invalid numeric hostname URLs Try to get the numeric octet parser to fail. The RFCs specify that we should fall back onto parsing them as domain names instead, and hence the unexpected legitimacy of out-of-range numbers.<commit_after>/* Copyright (c) 2009-2014 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "net.h"
#include "http-url.h"
#include "test-common.h"

struct valid_http_url_test {
	const char *url;
	enum http_url_parse_flags flags;
	struct http_url url_base;

	struct http_url url_parsed;
};

/* Valid HTTP URL tests */
static struct valid_http_url_test valid_url_tests[] = {
	/* Generic tests */
	{
		.url = "http://localhost",
		.url_parsed = {
			.host_name = "localhost" }
	},{
		.url = "http://www.%65%78%61%6d%70%6c%65.com",
		.url_parsed = {
			.host_name = "www.example.com" }
	},{
		.url = "http://www.dovecot.org:8080",
		.url_parsed = {
			.host_name = "www.dovecot.org",
			.port = 8080, .have_port = TRUE }
	},{
		.url = "http://127.0.0.1",
		.url_parsed = {
			.host_name = "127.0.0.1",
			.have_host_ip = TRUE }
#ifdef HAVE_IPV6
	},{
		.url = "http://[::1]",
		.url_parsed = {
			.host_name = "[::1]",
			.have_host_ip = TRUE }
	},{
		.url = "http://[::1]:8080",
		.url_parsed = {
			.host_name = "[::1]",
			.have_host_ip = TRUE,
			.port = 8080, .have_port = TRUE }
#endif
	},{
		.url = "http://user@api.dovecot.org",
		.flags = HTTP_URL_ALLOW_USERINFO_PART,
		.url_parsed = {
			.host_name = "api.dovecot.org", .user = "user" }
	},{
		.url = "http://userid:secret@api.dovecot.org",
		.flags = HTTP_URL_ALLOW_USERINFO_PART,
		.url_parsed = {
			.host_name = "api.dovecot.org",
			.user = "userid", .password = "<PASSWORD>" }
	},{
		.url = "http://su%3auserid:secret@api.dovecot.org",
		.flags = HTTP_URL_ALLOW_USERINFO_PART,
		.url_parsed = {
			.host_name = "api.dovecot.org",
			.user = "su:userid", .password = "<PASSWORD>" }
	},{
		.url = "http://www.example.com/"
			"?question=What%20are%20you%20doing%3f&answer=Nothing.",
		.url_parsed = {
			.path = "/",
			.host_name = "www.example.com",
			.enc_query = "question=What%20are%20you%20doing%3f&answer=Nothing." }
	},{
		/* These next 2 URLs don't follow the recommendations in
		   http://tools.ietf.org/html/rfc1034#section-3.5 and
		   http://tools.ietf.org/html/rfc3696
		   However they satisfy the grammar in
		   http://tools.ietf.org/html/rfc1123#section-2 and
		   http://tools.ietf.org/html/rfc952
		   so we should parse them.
		*/
		.url = "http://256.0.0.1/that/reverts/to/DNS",
		.url_parsed = {
			.path = "/that/reverts/to/DNS",
			.host_name = "256.0.0.1"
		}
	},{
		.url = "http://127.0.0.284/this/also/reverts/to/DNS",
		.url_parsed = {
			.path = "/this/also/reverts/to/DNS",
			.host_name = "127.0.0.284"
		}
	},{
		.url = "http://www.example.com/#Status%20of%20development",
		.flags = HTTP_URL_ALLOW_FRAGMENT_PART,
		.url_parsed = {
			.path = "/",
			.host_name = "www.example.com",
			.enc_fragment = "Status%20of%20development" }

	
	/* RFC 3986, Section 5.4. Reference Resolution Examples 
	 *
	 * Within a representation with a well defined base URI of
	 *
	 *  http://a/b/c/d;p?q
	 *
	 * a relative reference is transformed to its target URI as follows.
	 *
	 * 5.4.1. Normal Examples
	 */
{'fraction_non_alphanumeric': 0.1852112676056338, 'fraction_numerical': 0.038204225352112674, 'mean_word_length': 3.0462962962962963, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 16, 'xml': 0}, 'pii_count': 13, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '942728', 'n_tokens_mistral': 2602, 'n_tokens_neox': 2279, 'n_words': 424}