sub write_htaccess()

in t/modules/authz_core.t [42:89]


sub write_htaccess
{
    my $path = shift;
    my $merging = shift || "";
    my $container = shift || "";

    $text = "$path $merging $container @_";

    my $need_auth;
    my $content = "";
    $content .= "AuthMerging $merging\n" if $merging;

    if ($container) {
        $content .= "<Require$container>\n";
    }
    foreach (@_) {
        my $req = $_;
        my $not = "";
        if ($req =~ s/^\!//) {
            $not = 'not';
        }
        if ($req =~ /all/) {
            $content .= "Require $not $req\n";
        }
        elsif ($req =~ /user/) {
            # 'group' is correct, see comment about mod_authany below
            $content .= "Require $not group $req\n";
            $need_auth = 1;
        }
        else {
            $content .= "Require $not env allowed$req\n";
        }
    }
    if ($container) {
        $content .= "</Require$container>\n";
    }

    if ($need_auth) {
        $content .= "AuthType basic\n";
        $content .= "AuthName basic1\n";
        $content .= "AuthUserFile basic1\n";
        $content .= "AuthGroupFile groups1\n";
    }

    my $file = File::Spec->catfile(Apache::Test::vars('documentroot'),
        "/authz_core/$path/.htaccess");
    t_write_file($file, $content);
}