dsccommunity / SharePointDsc

The SharePointDsc PowerShell module provides DSC resources that can be used to deploy and manage a SharePoint farm
MIT License
247 stars 107 forks source link

SPShellAdmins: Member comparison was case sensitive. #1440

Closed ChristophHannappel closed 22 hours ago

ChristophHannappel commented 1 week ago

Pull Request (PR) description

The Member comparison of SPShellAdmins was case sensitive. But Active Directory User and Groups are not. This PR replaced the .Net .contains Method with the PowerShell Operator -contains and extended the unit tests.

This Pull Request (PR) fixes the following issues

Task list


This change is Reviewable

ChristophHannappel commented 1 week ago

@ykuijs the Build Pipeline has an issue with the GitVersion Task: Calculate ModuleVersion (GitVersion). I think thats outside of my pr. Could you take a look?

ykuijs commented 1 week ago

@ChristophHannappel, will have a look!

Have had that issue before.....is an issue in the new version of gitversion. Solution was to specifically specify an older version

ykuijs commented 1 week ago

@ChristophHannappel Could you please implement the following change: Add --version 5.12.0 to the end of this line: https://github.com/dsccommunity/SharePointDsc/blob/13408f4f835eeca0e598f093b4f20d1afefd4623/azure-pipelines.yml#L29

The line should say dotnet tool install --global GitVersion.Tool --version 5.12.0

ykuijs commented 1 week ago

An HQRM check is failing. Will check the cause tomorrow.

ChristophHannappel commented 1 week ago

An HQRM check is failing. Will check the cause tomorrow.

Context SharePointDsc.Reverse.psm1 WARNING: The file SharePointDsc.Reverse.psm1 contains a suppression of the required PS Script Analyser rule PSAvoidUsingWriteHost. Please remove the rule suppression. [-] Should not suppress any required PS Script Analyzer rules 141ms Expected $false, but got $true. 125: $requiredRuleIsSuppressed | Should -BeFalse at <ScriptBlock>, D:\a\1\s\output\RequiredModules\DscResource.Test\0.16.3\Tests\QA\PSSAResource.common.v4.Tests.ps1: line 125

Thank you :)

codecov[bot] commented 1 week ago

Codecov Report

Attention: Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 84%. Comparing base (b310e7d) to head (db9df9b). Report is 13 commits behind head on master.

Files with missing lines Patch % Lines
...sources/MSFT_SPShellAdmins/MSFT_SPShellAdmins.psm1 83% 2 Missing :warning:
Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/dsccommunity/SharePointDsc/pull/1440/graphs/tree.svg?width=650&height=150&src=pr&token=pEGO3aoxXm&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dsccommunity)](https://app.codecov.io/gh/dsccommunity/SharePointDsc/pull/1440?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dsccommunity) ```diff @@ Coverage Diff @@ ## master #1440 +/- ## ====================================== Coverage 84% 84% ====================================== Files 145 145 Lines 22809 22809 ====================================== + Hits 19236 19246 +10 + Misses 3573 3563 -10 ``` | [Files with missing lines](https://app.codecov.io/gh/dsccommunity/SharePointDsc/pull/1440?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dsccommunity) | Coverage Ξ” | | |---|---|---| | [...sources/MSFT\_SPShellAdmins/MSFT\_SPShellAdmins.psm1](https://app.codecov.io/gh/dsccommunity/SharePointDsc/pull/1440?src=pr&el=tree&filepath=SharePointDsc%2FDSCResources%2FMSFT_SPShellAdmins%2FMSFT_SPShellAdmins.psm1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dsccommunity#diff-U2hhcmVQb2ludERzYy9EU0NSZXNvdXJjZXMvTVNGVF9TUFNoZWxsQWRtaW5zL01TRlRfU1BTaGVsbEFkbWlucy5wc20x) | `61% <83%> (+1%)` | :arrow_up: |

🚨 Try these New Features:

johlju commented 1 week ago

It was a change in module DscResource.Test to make that test run on just the source files. Prior to the change the HQRM test was run on both built module and source files but apparently due to a bug that test was never run on source files before. πŸ€”

If you want to keep Write-Host I suggest excluding that file for HQRM tests, add the relative path to the file here which I think should ignore the file:

https://github.com/dsccommunity/SharePointDsc/blob/13408f4f835eeca0e598f093b4f20d1afefd4623/build.yaml#L93-L94

Alternative I recommend changing Write-Host to:

Write-Information -MessageData 'MyMessage' -InformationAction 'Continue'
ChristophHannappel commented 1 week ago

If you want to keep Write-Host I suggest excluding that file for HQRM tests, add the relative path to the file here which I think should ignore the file:

https://github.com/dsccommunity/SharePointDsc/blob/13408f4f835eeca0e598f093b4f20d1afefd4623/build.yaml#L93-L94

I've added the file to the List, but that did not help.

@ykuijs would it be ok if I replaced the Write-Host with Write-Information as @johlju suggested?

johlju commented 1 week ago

Hmm strange I thought that would do it. @ChristophHannappel Can you test exclude the name SharePointDsc.Reverse to verify.

It should filter out the excluded files here: https://github.com/dsccommunity/DscResource.Test/blob/14acda0bc0a6a9698bfb8fd41da42adfe08b09f0/source/Tests/QA/PSSAResource.common.v4.Tests.ps1#L82

Using the filter: https://github.com/dsccommunity/DscResource.Test/blob/14acda0bc0a6a9698bfb8fd41da42adfe08b09f0/source/Private/WhereSourceFileNotExcluded.ps1#L1

If above doesn't work then there must be a bug in DscResource.Test, need to debug to find it. I submit a bug in that repo. Maybe @dan-hughes have some input?

But do suggest replace Write-Host so hopefully @ykuijs is okay with that.

johlju commented 1 week ago

It was a change in module DscResource.Test to make that test run on just the source files. Prior to the change the HQRM test was run on both built module and source files but apparently due to a bug that test was never run on source files before. πŸ€”

Not true, that change hasn't been released yet. My bad. There must be something else going on in 0.16.3 release.

@ChristophHannappel can we test to see if the latest preview will help with this, there are a lot of improvements there. Change:

https://github.com/dsccommunity/SharePointDsc/blob/13408f4f835eeca0e598f093b4f20d1afefd4623/RequiredModules.psd1#L20

too:

    'DscResource.Test'     = @{
        Version    = 'latest'
        Parameters = @{
            AllowPrerelease = $true
        }
    }

That will use the preview release 0.17.0-preview0003.

ykuijs commented 1 week ago

@ChristophHannappel, not sure what the impact will be if we remove Write-Host. I know we have been using Write-Host to specifically write to the screen instead of in the pipeline so we can use formatting, etc.

I see that the tests keep failing. In the last change you didn't specify the file extension. Can you please add that?

johlju commented 1 week ago

not sure what the impact will be if we remove Write-Host. I know we have been using Write-Host to specifically write to the screen instead of in the pipeline so we can use formatting, etc.

The command Write-Information uses the information stream to output messages to the console. But it cannot use text color without using ansi-sequences, but PS5 doesn't handle ansi-sequences either so text color is not possible. More input: https://stackoverflow.com/questions/38523369/write-host-vs-write-information-in-powershell-5

johlju commented 1 week ago

@ChristophHannappel thanks for testing the changes, it seems it didn't do anything. I won't have time to debubg DscResource.Test, but could try to do it this weekend - it could probably be a problem in the future for others as well.

@ykuijs I really suggest to move away from Write-Host for this particular problem, then the code will still be tested correctly and not excluded from all HQRM tests.

dan-hughes commented 1 week ago

HQRM issue is probably this commit.

I do not see any further changes to the Pester v4 HQRM tests. It is working as expected, required rules are not able to be disabled in the current test.

See here for a workaround but this disables required rule checking.

johlju commented 1 week ago

I added this issue https://github.com/dsccommunity/DscResource.Test/issues/142 to track that it is seemingly not possible to exclude a source file from HQRM testing.

dan-hughes commented 6 days ago

dsccommunity/DscResource.Test#143 waiting to be merged that fixes the HQRM issue you are having.

The path in build.yml required is the path to the psm1 file relative to the source directory which in this case is the SharePointDsc directory inside the module.

dan-hughes commented 6 days ago

Therefore the entry you would require is: - Modules/SharePointDsc.Reverse/SharePointDsc.Reverse.psm1

All the other entries including the output can be removed as these will not do anything.

ykuijs commented 6 days ago

@ChristophHannappel Once the other PR is merged: Can you update the build.yaml with the string suggested by @dan-hughes, so that the correct path will be excluded?

ChristophHannappel commented 5 days ago

@ChristophHannappel Once the other PR is merged: Can you update the build.yaml with the string suggested by @dan-hughes, so that the correct path will be excluded?

Sure thing.

@dan-hughes: will that also be a preview release?

dan-hughes commented 5 days ago

Yes. Unless one of the maintainers decides to trigger a full release.

johlju commented 5 days ago

We can test this PR with the preview and if it works I can release a full release of DscResource.Test. But I wont have time to review @dan-hughes PR until this weekend. To much to do at the day job 😊

ChristophHannappel commented 5 days ago

The

We can test this PR with the preview and if it works I can release a full release of DscResource.Test. But I wont have time to review @dan-hughes PR until this weekend. To much to do at the day job 😊

The Preview worked πŸ₯³ Thank you very much.

@ykuijs I found another Bug in the SPSite Ressource which i will fix next. So if you can wait with the next Release both fixes could be shipped :)

ykuijs commented 5 days ago

@ChristophHannappel Great news! Sure, no problem. Just submit the other fix in a PR and I will release a new version after merging that PR.

@johlju and @dan-hughes thanks a lot for your help in fixing this issue!

dan-hughes commented 5 days ago

I'd like to take credit, but the PR was pulled as it wasn't the correct fix.

Nice to know what the workaround is though!

ChristophHannappel commented 5 days ago

Seems like I have to fix some tests. @ykuijs do you have a tip how to run the tests only for one Resource? So I can avoid the whole build.ps1 experience. Thank you

dan-hughes commented 4 days ago

Seems like I have to fix some tests. @ykuijs do you have a tip how to run the tests only for one Resource? So I can avoid the whole build.ps1 experience. Thank you

You can just specify the path to the test file in the Script key in build.yml.

It will not help with code coverage but it helps with test runtime.

johlju commented 4 days ago

t will not help with code coverage but it helps with test runtime.

If the code coverage is extensive it can be turned of by also passing -CodeCoverageThreshold 0

It should also possible to use Invoke-Pester directly after running ./build.ps1 -Task noop (onse for each session to set up the environment).

ykuijs commented 4 days ago

I believe it is also possible to run the .\build.ps1 -Tasks Build once and then just run the Pester ps1 file of the resource you would like to test.

ykuijs commented 4 days ago

@ChristophHannappel Now that all tests have completed successfully, can this PR be merged?

ChristophHannappel commented 4 days ago

@ykuijs Yes please.

At Everyone: Thank you for helping so quickly with my pipeline issues