Private/Test-KadenBetaInvitation.ps1
|
function Test-KadenBetaInvitation { <# .SYNOPSIS Accept a PascalCase beta invitation passphrase that ends with Beta. .DESCRIPTION The passphrase must be five curated words in PascalCase with no spaces, then the literal Beta suffix. This is a cohort signal only. It does not enforce use, confidentiality, licensing, or authorization. #> [CmdletBinding()] param( [Parameter(Mandatory = $true)] [AllowEmptyString()] [string]$Invitation ) $invalidForm = 'KDN-BETA-INVITATION-INVALID: Beta invitation must be five curated PascalCase words with no spaces, ending in Beta.' if ([string]::IsNullOrWhiteSpace($Invitation) -or ($Invitation -match '\s')) { return [pscustomobject]@{ Valid = $false Message = $invalidForm } } if (-not $Invitation.EndsWith('Beta', [System.StringComparison]::Ordinal)) { return [pscustomobject]@{ Valid = $false Message = 'KDN-BETA-INVITATION-INVALID: Beta invitation must end with the literal word Beta.' } } $core = $Invitation.Substring(0, $Invitation.Length - 4) if ([string]::IsNullOrEmpty($core)) { return [pscustomobject]@{ Valid = $false Message = $invalidForm } } $allowed = @{} foreach ($word in @(Get-KadenInvitationWordList)) { $token = ConvertTo-KadenInvitationToken -Word $word $allowed[$token] = $true } $tokenMatches = [regex]::Matches($core, '[A-Z][a-z]*') if ($tokenMatches.Count -ne 5) { return [pscustomobject]@{ Valid = $false Message = $invalidForm } } $rebuilt = '' foreach ($match in $tokenMatches) { $token = $match.Value $rebuilt += $token if (-not $allowed.ContainsKey($token)) { return [pscustomobject]@{ Valid = $false Message = $invalidForm } } } if ($rebuilt -cne $core) { return [pscustomobject]@{ Valid = $false Message = $invalidForm } } return [pscustomobject]@{ Valid = $true Message = 'Beta acknowledgement accepted. Start with docs/kaden/getting-started.md.' } } |