Blame tests/regression/config/10-misc-directives.t

Packit 284210
### Misc directive tests
Packit 284210
Packit 284210
### TODO:
Packit 284210
# SecTmpDir
Packit 284210
# SecUploadKeepFiles
Packit 284210
# SecChrootDir
Packit 284210
# SecGuardianLog
Packit 284210
Packit 284210
# SecDefaultAction
Packit 284210
{
Packit 284210
	type => "config",
Packit 284210
	comment => "SecDefaultAction",
Packit 284210
	conf => qq(
Packit 284210
		SecRuleEngine on
Packit 284210
		SecDefaultAction "phase:1,deny,status:500"
Packit 284210
		SecRule REQUEST_URI "test.txt" "id:500241"
Packit 284210
	),
Packit 284210
	match_log => {
Packit 284210
		error => [ qr/ModSecurity: Access denied with code 500 \(phase 1\)/, 1 ],
Packit 284210
	},
Packit 284210
	match_response => {
Packit 284210
		status => qr/^500$/,
Packit 284210
	},
Packit 284210
	request => new HTTP::Request(
Packit 284210
		GET => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
Packit 284210
	),
Packit 284210
},
Packit 284210
Packit 284210
# SecServerSignature
Packit 284210
{
Packit 284210
	type => "config",
Packit 284210
	comment => "SecServerSignature On",
Packit 284210
	conf => qq(
Packit 284210
		SecServerSignature "NewServerSignature"
Packit 284210
	),
Packit 284210
	match_response => {
Packit 284210
		status => qr/^200$/,
Packit 284210
		raw => qr/^Server: +NewServerSignature$/m,
Packit 284210
	},
Packit 284210
	request => new HTTP::Request(
Packit 284210
		GET => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
Packit 284210
	),
Packit 284210
},
Packit 284210
Packit 284210
# SecDataDir
Packit 284210
{
Packit 284210
	type => "config",
Packit 284210
	comment => "SecDataDir",
Packit 284210
	conf => qq(
Packit 284210
		SecRuleEngine On
Packit 284210
		SecDataDir "$ENV{DATA_DIR}"
Packit 284210
		SecAction initcol:ip=%{REMOTE_ADDR},setvar:ip.dummy=1,pass,id:500085
Packit 284210
	),
Packit 284210
	match_log => {
Packit 284210
		error => [ qr/ModSecurity: Warning. Unconditional match in SecAction\./, 1 ],
Packit 284210
	},
Packit 284210
	match_file => {
Packit 284210
		"$ENV{DATA_DIR}/ip.pag" => qr/\x00\x06dummy\x00\x00\x021\x00/,
Packit 284210
	},
Packit 284210
	match_response => {
Packit 284210
		status => qr/^200$/,
Packit 284210
	},
Packit 284210
	request => new HTTP::Request(
Packit 284210
		GET => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
Packit 284210
	),
Packit 284210
},
Packit 284210
Packit 284210
# SecTmpDir/SecUploadDir/SecUploadKeepFiles
Packit 284210
{
Packit 284210
	type => "config",
Packit 284210
	comment => "SecTmpDir/SecUploadDir/SecUploadKeepFiles",
Packit 284210
	conf => qq(
Packit 284210
		SecRuleEngine On
Packit 284210
		SecRequestBodyAccess On
Packit 284210
		SecDebugLog $ENV{DEBUG_LOG}
Packit 284210
		SecDebugLogLevel 4
Packit 284210
		SecTmpDir "$ENV{TEMP_DIR}"
Packit 284210
		SecUploadKeepFiles On
Packit 284210
		SecUploadDir "$ENV{UPLOAD_DIR}"
Packit 284210
	),
Packit 284210
	test => sub {
Packit 284210
		# Get the filename and make sure the file exists
Packit 284210
		my $fn = match_log(debug => qr/Moved file from .* to ".*"\./, 5);
Packit 284210
		die "Failed to determine uploaded filename\n" unless (defined $fn);
Packit 284210
Packit 284210
		$fn =~ s/Moved file from .* to "(.*)"\..*/$1/;
Packit 284210
		die "File does not exist: $fn\n" unless (-e $fn);
Packit 284210
Packit 284210
		# Check the contents of the file
Packit 284210
		return 0 if (match_file($fn, qr/^TESTFILE$/m));
Packit 284210
		
Packit 284210
		msg("Failed to match contents of uploaded file: $fn");
Packit 284210
		return 1;
Packit 284210
	},
Packit 284210
	match_log => {
Packit 284210
		debug => [ qr/Created temporary file.*$ENV{TEMP_DIR}/, 1 ],
Packit 284210
		-debug => [ qr/Failed to /, 1 ],
Packit 284210
	},
Packit 284210
	match_response => {
Packit 284210
		status => qr/^200$/,
Packit 284210
	},
Packit 284210
	request => new HTTP::Request(
Packit 284210
		POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
Packit 284210
		[
Packit 284210
			"Content-Type" => "multipart/form-data; boundary=---------------------------19813181771830765643996187206",
Packit 284210
		],
Packit 284210
		q(-----------------------------19813181771830765643996187206
Packit 284210
Content-Disposition: form-data; name="upload-file"; filename="test"
Packit 284210
Content-Type: application/octet-stream
Packit 284210
Packit 284210
TESTFILE
Packit 284210
-----------------------------19813181771830765643996187206
Packit 284210
Content-Disposition: form-data; name="file"
Packit 284210
Packit 284210
Upload File
Packit 284210
-----------------------------19813181771830765643996187206--),
Packit 284210
	),
Packit 284210
},
Packit 284210
Packit 284210
# SecWebAppId
Packit 284210
{
Packit 284210
	type => "config",
Packit 284210
	comment => "SecWebAppId",
Packit 284210
	conf => qq(
Packit 284210
		SecRuleEngine On
Packit 284210
		SecRequestBodyAccess On
Packit 284210
		SecDebugLog $ENV{DEBUG_LOG}
Packit 284210
		SecDebugLogLevel 4
Packit 284210
		SecAuditLog "$ENV{AUDIT_LOG}"
Packit 284210
		SecAuditEngine RelevantOnly
Packit 284210
		SecWebAppId "app-1"
Packit 284210
		SecAction "pass,log,auditlog,id:1"
Packit 284210
	),
Packit 284210
	match_log => {
Packit 284210
		error => [ qr/Warning\. Unconditional match in SecAction\./, 1 ],
Packit 284210
		debug => [ qr/Warning\. Unconditional match in SecAction\./, 1 ],
Packit 284210
		audit => [ qr/^WebApp-Info: "app-1"/m, 1 ],
Packit 284210
	},
Packit 284210
	match_response => {
Packit 284210
		status => qr/^200$/,
Packit 284210
	},
Packit 284210
	request => new HTTP::Request(
Packit 284210
		GET => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
Packit 284210
	),
Packit 284210
},