jpsider / RestPS

Simple ReST Framework for Powershell
MIT License
113 stars 30 forks source link

Rewrite code for Basic Authentication #44

Closed accc703 closed 4 years ago

accc703 commented 4 years ago

Decode the Authorization header, and compare the user records in Get-RestUserAuth.ps1

jpsider commented 4 years ago

Looks like the build failed due to 'PSAvoidTrailingWhitespace' Not sure which line, but one of them has some extra whitepsace.

jpsider commented 4 years ago

Line 9, 43

accc703 commented 4 years ago

Line 9, 43

Just removed the whitespace at the line mentioned

jpsider commented 4 years ago

https://ci.appveyor.com/project/JustinSider/restps/builds/32584653

hmm, still missing something. I'm on my phone, so I can't take a look now. you can run scriptanalyzer locally on that file to get the exact lines.

accc703 commented 4 years ago

https://ci.appveyor.com/project/JustinSider/restps/builds/32584653

Thank you. I am totally new on github

jpsider commented 4 years ago

Github can be tricky! - I'm happy having folks conrtibute! Instead of doing a foreach loop. What about doing a where, that way you can limit it to one check. `# Untested

$RequestUserName,$RequestPass = $DecodedAuthString -split (":") $AllowedUser = $RestUserAuth | Where-Object {$_.UserName -eq "$RequestUserName"}

If(($AllowedUser | Measure-Object).Count -eq 1) {

Perform the check

} else {

Incorrect number of Matches

}`

accc703 commented 4 years ago

Measure-Object

If using WHERE, would the following code logically correct, by checking the username and password at the same line?

$AllowedUser = $RestUserAuth | Where-Object {($.UserName -eq "$RequestUserName") -And ($.SystemAuthString -eq "$RequestPass)} If(($AllowedUser | Measure-Object).Count -eq 1) { $script:VerifyStatus = $true } else { $script:VerifyStatus = $false }`

jpsider commented 4 years ago

In theory, yes! - But it would need to functionally be tested.

accc703 commented 4 years ago

Let me try to program and test, and create pull again.