tests/UrlAcl.tests.ps1

Describe 'UrlAcl' {
    BeforeAll {
        Get-UrlAcl -Url http://+:99/ -ErrorAction SilentlyContinue | Select-Object { [pscustomobject]$_.Url } | Remove-UrlAcl -Confirm:$false
        Add-UrlAcl -Url http://+:99/ -User (whoami)
    }

    AfterAll {
        Get-UrlAcl -Url http://+:99/ -ErrorAction SilentlyContinue | Remove-UrlAcl -Confirm:$false
    }

    It 'can get urlacl entries' {
        $entries = @(Get-UrlAcl)
        $entries.Count | Should -BeGreaterThan 0
    }

    It 'can get a single urlacl' {
        $list = @(Get-UrlAcl -Url http://+:99/)
        $list.Count | Should -BeExactly 1
    }

    It 'fails when an entry is not found' {
        { Get-Urlacl -Url http://+:100/ -ErrorAction Stop } | Should -Throw
    }

    It 'fails when removing a non-existing urlacl entry' {
        { Remove-UrlAcl -Url http://+:100/ -ErrorAction Stop -Confirm:$false } | Should -Throw
    }

    It 'succeeds at removing an existing urlacl entry' {
        Remove-UrlAcl -Url http://+:99/ -Confirm:$false
        (Get-UrlAcl -Url http://+:99/ -ErrorAction SilentlyContinue ) | Should -BeNullOrEmpty
    }

    It 'can create a new urlacl entry with PassThru and pipe it to Remove-UrlAcl without error' {
        {
            $acl = Add-UrlAcl -Url http://+:100/ -User (whoami) -PassThru -ErrorAction Stop
            $acl | Remove-UrlAcl -ErrorAction Stop -Confirm:$false
        } | Should -Not -Throw
    }
}