tests/Test-ReauthWithCode.ps1

function Test-ReauthWithCode {
    [CmdletBinding()]
    param (
        # Aligned
        # Define your parameters here
    )

    begin {
        # Dot source the class script if necessary
        #. .\source\Classes\CISAuditResult.ps1
        # Initialization code, if needed
    }

    process {
        # 7.2.10 (L1) Ensure reauthentication with verification code is restricted

        # Retrieve reauthentication settings for SharePoint Online
        $SPOTenantReauthentication = Get-SPOTenant | Select-Object EmailAttestationRequired, EmailAttestationReAuthDays
        $isReauthenticationRestricted = $SPOTenantReauthentication.EmailAttestationRequired -and $SPOTenantReauthentication.EmailAttestationReAuthDays -le 15

        # Prepare failure reasons and details based on compliance
        $failureReasons = if (-not $isReauthenticationRestricted) {
            "Reauthentication with verification code does not require reauthentication within 15 days or less."
        }
        else {
            "N/A"
        }

        $details = "EmailAttestationRequired: $($SPOTenantReauthentication.EmailAttestationRequired); EmailAttestationReAuthDays: $($SPOTenantReauthentication.EmailAttestationReAuthDays)"

        # Create and populate the CISAuditResult object
        $params = @{
            Rec            = "7.2.10"
            Result         = $isReauthenticationRestricted
            Status         = if ($isReauthenticationRestricted) { "Pass" } else { "Fail" }
            Details        = $details
            FailureReason  = $failureReasons
        }
        $auditResult = Initialize-CISAuditResult @params
    }

    end {
        # Return auditResult
        return $auditResult
    }
}