<commit_before>function Get-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Collections.Hashtable])]
    param
    (
        [parameter(Mandatory = $true)]  [System.String]  $WebAppUrl,
        [parameter(Mandatory = $true)]  [System.String]  $SuperUserAlias,
        [parameter(Mandatory = $true)]  [System.String]  $SuperReaderAlias,
        [parameter(Mandatory = $false)] [System.Boolean] $SetWebAppPolicy = $true,
        [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
    )

    Write-Verbose -Message "Getting cache accounts for $WebAppUrl"

    $result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
        $params = $args[0]
        
        $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue

        if ($null -eq $wa) { return @{
            WebAppUrl = $params.WebAppUrl
            SuperUserAlias = $null
            SuperReaderAlias = $null
            SetWebAppPolicy = $false
            InstallAccount = $params.InstallAccount
        } }
        
        $returnVal = @{}
        $returnVal.Add("WebAppUrl", $params.WebAppUrl)
        if ($wa.Properties.ContainsKey("portalsuperuseraccount")) { 
            $returnVal.Add("SuperUserAlias", $wa.Properties["portalsuperuseraccount"])
        } else {
            $returnVal.Add("SuperUserAlias", "")
        }
        if ($wa.Properties.ContainsKey("portalsuperreaderaccount")) { 
            $returnVal.Add("SuperReaderAlias", $wa.Properties["portalsuperreaderaccount"])
        } else {
            $returnVal.Add("SuperReaderAlias", "")
        }
        $returnVal.Add("InstallAccount", $params.InstallAccount)
        
        $policiesSet = $true
        if ($wa.UseClaimsAuthentication -eq $true) {
            if ($wa.Policies.UserName -notcontains ((New-SPClaimsPrincipal -Identity $params.SuperReaderAlias -IdentityType WindowsSamAccountName).ToEncodedString())) { $policiesSet = $false }
            if ($wa.Policies.UserName -notcontains ((New-SPClaimsPrincipal -Identity $params.SuperUserAlias -IdentityType WindowsSamAccountName).ToEncodedString())) { $policiesSet = $false }    
        } else {
            if ($wa.Policies.UserName -notcontains $params.SuperReaderAlias) { $policiesSet = $false }
            if ($wa.Policies.UserName -notcontains $params.SuperUserAlias) { $policiesSet = $false }
        }
        $returnVal.Add("SetWebAppPolicy", $policiesSet)
        
        return $returnVal
    }
    return $result
}


function Set-TargetResource
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true)]  [System.String]  $WebAppUrl,
        [parameter(Mandatory = $true)]  [System.String]  $SuperUserAlias,
        [parameter(Mandatory = $true)]  [System.String]  $SuperReaderAlias,
        [parameter(Mandatory = $false)] [System.Boolean] $SetWebAppPolicy = $true,
        [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount<commit_msg>Bug fix for claims accounts in cache values<commit_after>function Get-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Collections.Hashtable])]
    param
    (
        [parameter(Mandatory = $true)]  [System.String]  $WebAppUrl,
        [parameter(Mandatory = $true)]  [System.String]  $SuperUserAlias,
        [parameter(Mandatory = $true)]  [System.String]  $SuperReaderAlias,
        [parameter(Mandatory = $false)] [System.Boolean] $SetWebAppPolicy = $true,
        [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
    )

    Write-Verbose -Message "Getting cache accounts for $WebAppUrl"

    $result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
        $params = $args[0]
        
        $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue

        if ($null -eq $wa) { return @{
            WebAppUrl = $params.WebAppUrl
            SuperUserAlias = $null
            SuperReaderAlias = $null
            SetWebAppPolicy = $false
            InstallAccount = $params.InstallAccount
        } }
        
        $returnVal = @{
            InstallAccount = $params.InstallAccount
            WebAppUrl = $params.WebAppUrl
        }
        
        $policiesSet = $true
        if ($wa.UseClaimsAuthentication -eq $true) {
            if ($wa.Properties.ContainsKey("portalsuperuseraccount")) {
                $claim = New-SPClaimsPrincipal -Identity $wa.Properties["portalsuperuseraccount"] -IdentityType EncodedClaim -ErrorAction SilentlyContinue
                if ($claim -ne $null) {
                    $returnVal.Add("SuperUserAlias", $claim.Value)
                } else {
                    $returnVal.Add("SuperUserAlias", "")
                }
            } else {
                $returnVal.Add("SuperUserAlias", "")
            }
            if ($wa.Properties.ContainsKey("portalsuperreaderaccount")) {
                $claim = New-SPClaimsPrincipal -Identity $wa.Properties["portalsuperreaderaccount"] -IdentityType EncodedClaim -ErrorAction SilentlyContinue
                if ($claim -ne $null) {
                    $returnVal.Add("SuperReaderAlias", $claim.Value)
                } else {
                    $returnVal.Add("SuperReaderAlias", "")
                }
            } else {
                $returnVal.Add("SuperReaderAlias", "")
            }
            if ($wa.Policies.UserName -notcontains ((New-SPClaimsPrincipal -Identity $params.SuperReaderAlias -IdentityType WindowsSamAccountName).ToEncodedString())) { $policiesSet = $false }
            if ($wa.Policies.UserName -notcontains ((New-SPClaimsPrincipal -Identity $params.SuperUserAlias -IdentityType WindowsSamAccountName).ToEncodedString())) { $policiesSet = $false }    
        } else {
            if ($wa.Properties.ContainsKey("portalsuperuseraccount")) { 
            $returnVal.Add("SuperUserAlias", $wa.Properties["portalsuperuseraccount"])
            } else {
                $returnVal.Add("SuperUserAlias", "")
            }
            if ($wa.Properties.ContainsKey("portalsuperreaderaccount")) { 
                $returnVal.Add("SuperReaderAlias", $wa.Properties["portalsuperreaderaccount"])
            } else {
                $returnVal.Add("SuperReaderAlias", "")
            }
            if ($wa.Policies.UserName -notcontains $params.SuperReaderAlias) { $policiesSet = $false }
            if ($wa.Policies.UserName -notcontains $params.SuperUserAlias) { $policiesSet = $false }
        }
        $returnVal.Add("SetWebAppPolicy", $policiesSet)
        
        return $returnVal
    }
    return $result
}


function Set-TargetResource
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true)]  [System.String]  $WebAppUrl,
        [parameter(Mandatory = $true)]  [System.String]  $SuperUserAlias,
        [parameter(Mandatory = $true)]  [System.String]  $SuperReaderAlias,
        [parameter(Mandatory = $false)] [System.Boolean] $SetWebAppPolicy = $true,
        [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
{'fraction_non_alphanumeric': 0.12101822228404507, 'fraction_numerical': 0.00027820280984837946, 'mean_word_length': 2.5717834078489816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '5328812', 'n_tokens_mistral': 2031, 'n_tokens_neox': 2008, 'n_words': 346}