Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdcsAuthorityInformationAccess: Always makes a change #128, #138 #141

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dan-hughes
Copy link
Contributor

@dan-hughes dan-hughes commented Apr 18, 2024

Pull Request (PR) description

Removed the AllowRestartService parameter from being tested/compared.
Updated Get-CaAiaUriList to force a System.String[] to be returned regardless of single or multiple values.

This Pull Request (PR) fixes the following issues

Task list

  • Added an entry under the Unreleased section of the change log in the CHANGELOG.md.
    Entry should say what was changed, and how that affects users (if applicable).
  • Resource documentation added/updated in README.md in resource folder.
  • Resource parameter descriptions added/updated in schema.mof
    and comment-based help.
  • Comment-based help added/updated.
  • Localization strings added/updated in all localization files as appropriate.
  • Examples appropriately added/updated.
  • Unit tests added/updated. See DSC Resource Testing Guidelines.
  • Integration tests added/updated (where possible). See DSC Resource Testing Guidelines.
  • New/changed code adheres to DSC Resource Style Guidelines and Best Practices.

This change is Reviewable

Copy link

codecov bot commented Apr 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98%. Comparing base (60f9961) to head (e9d220b).

Additional details and impacted files

Impacted file tree graph

@@         Coverage Diff         @@
##           main   #141   +/-   ##
===================================
  Coverage    98%    98%           
===================================
  Files         8      8           
  Lines       514    515    +1     
===================================
+ Hits        505    506    +1     
  Misses        9      9           

@dan-hughes
Copy link
Contributor Author

dan-hughes commented Apr 18, 2024

@johlju, I looked at this a few weeks ago then found out the build was not working.

It fixes #138 but I also think it may fix #128 as they look to be mentioning the same things.

On tests, I'd need to possibly have mocks with only single AIA and OCSP values in to begin with. Thoughts?

@PlagueHO PlagueHO added the needs review The pull request needs a code review. label Apr 18, 2024
@PlagueHO PlagueHO self-assigned this Apr 18, 2024
@johlju johlju requested a review from PlagueHO April 21, 2024 06:55
Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On tests, I'd need to possibly have mocks with only single AIA and OCSP values in to begin with. Thoughts?

I think we should test that no value (null?), single value, and multiple values are returned. 🤔

Reviewed 1 of 2 files at r1, all commit messages.
Reviewable status: 1 of 3 files reviewed, 3 unresolved discussions (waiting on @dan-hughes and @PlagueHO)


source/DSCResources/DSC_AdcsAuthorityInformationAccess/DSC_AdcsAuthorityInformationAccess.psm1 line 37 at r2 (raw file):

        IsSingleInstance = 'Yes'
        AiaUri = Get-CaAiaUriList -ExtensionType 'AddToCertificateAia'
        OcspUri = Get-CaAiaUriList -ExtensionType 'AddToCertificateOcsp'

We should check if Get-CaAiaUriList is null or empty, if it is not we should cast the value to an string array - otherwise we return $null.

Same for both values. Also see other comment.


source/DSCResources/DSC_AdcsAuthorityInformationAccess/DSC_AdcsAuthorityInformationAccess.psm1 line 209 at r2 (raw file):

    $null = $PSBoundParameters.Remove('IsSingleInstance')
    $null = $PSBoundParameters.Remove('AllowRestartService')

We should tell Test-DscParameterState to exclude the parameter from testing instead of removing it (as is also added to the return value of Get-TargetResource). There should be a parameter for that in the command.


source/DSCResources/DSC_AdcsAuthorityInformationAccess/DSC_AdcsAuthorityInformationAccess.psm1 line 239 at r2 (raw file):

    $UriList = [System.String[]] (Get-CAAuthorityInformationAccess | Where-Object -Property $ExtensionType -Eq $true).Uri
    return ,$UriList

I think we should avoid the unary operator. I think it is better to cast the returned value in the next step instead to make sure we actually get a string array unless it returns $null.

Copy link
Contributor Author

@dan-hughes dan-hughes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 3 files reviewed, 3 unresolved discussions (waiting on @johlju and @PlagueHO)


source/DSCResources/DSC_AdcsAuthorityInformationAccess/DSC_AdcsAuthorityInformationAccess.psm1 line 209 at r2 (raw file):

Previously, johlju (Johan Ljunggren) wrote…

We should tell Test-DscParameterState to exclude the parameter from testing instead of removing it (as is also added to the return value of Get-TargetResource). There should be a parameter for that in the command.

That's a nicer solution. I'm assuming the IsSingleInstance parameter needs to go into the exclude too?


source/DSCResources/DSC_AdcsAuthorityInformationAccess/DSC_AdcsAuthorityInformationAccess.psm1 line 239 at r2 (raw file):

Previously, johlju (Johan Ljunggren) wrote…

I think we should avoid the unary operator. I think it is better to cast the returned value in the next step instead to make sure we actually get a string array unless it returns $null.

This function returns $null, System.String[] or System.String if the call to Get-CAAuthorityInformationAccess is a single value.

Would it be 'cleaner' to ensure that this function only returns $null or System.String[]?

Or is the checking logic explicitly required to work around this behaviour?

Copy link
Contributor Author

@dan-hughes dan-hughes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 3 files reviewed, 3 unresolved discussions (waiting on @johlju and @PlagueHO)


source/DSCResources/DSC_AdcsAuthorityInformationAccess/DSC_AdcsAuthorityInformationAccess.psm1 line 37 at r2 (raw file):

Previously, johlju (Johan Ljunggren) wrote…

We should check if Get-CaAiaUriList is null or empty, if it is not we should cast the value to an string array - otherwise we return $null.

Same for both values. Also see other comment.

Taking a fresh look at this Get-CaAiaUriList will never return System.String[] on it's own as PowerShell will do it's thing and unwrap the values.
If the result is cast outside as you suggested, is a $null check required as PowerShell should explicitly convert $null into an empty string in this case?


source/DSCResources/DSC_AdcsAuthorityInformationAccess/DSC_AdcsAuthorityInformationAccess.psm1 line 239 at r2 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

This function returns $null, System.String[] or System.String if the call to Get-CAAuthorityInformationAccess is a single value.

Would it be 'cleaner' to ensure that this function only returns $null or System.String[]?

Or is the checking logic explicitly required to work around this behaviour?

As per above I'm not sure it will ever return a System.String[]. Changed just to System.String, is this a valid approach?

@johlju
Copy link
Member

johlju commented Jun 1, 2024

If you rebase this one I continue with this one. 🙂

@dan-hughes
Copy link
Contributor Author

I really messed up when trying to merge. I think it's all back to where it should be now.

What's going to be the optimal solution for this? The Get-CaAiaUriList should return a string or string[].

@johlju
Copy link
Member

johlju commented Jun 11, 2024

I will try to get back to this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review The pull request needs a code review.
Projects
None yet
3 participants