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

RTA: xSMTP #162

Closed
wants to merge 16 commits into from
Closed

RTA: xSMTP #162

wants to merge 16 commits into from

Conversation

nzspambot
Copy link

@nzspambot nzspambot commented Jun 14, 2016

Ok here is a 95%(?) complete xSMTP resource

Things to do

  • add more unit tests for the helper function e: Added these tests
  • validate sets on the param inputs

Things which don't work

  • Some settings refuse to be set. It maybe because other params are outside acceptable ranges but unsure at this stage. Needs more investigation. As a result appveyor should not work.
  • As mentioned the logging is interesting there seems on the face of it no way to enable logging which renders the logging options moot

Things to note

  • All params (bar one) are [String] as if cast as say [Int] the Get-TargetResource in the integration tests will take a 💩

This change is Reviewable

@tysonjhayes
Copy link

Not to be a pest but would it be possible to call it SMTPServer or SMTPHost or something to clarify what its purpose is?


Reviewed 7 of 7 files at r1.
Review status: all files reviewed at latest revision, 30 unresolved discussions, some commit checks failed.


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 11 [r1] (raw file):

    # culture="en-US"
    ConvertFrom-StringData -StringData @'
ErrorSMTPDiscoveryFailure = No SMTP Virutal server found.

Going to need to add four spaces to all of these or @mbreakey3 will come scowl at you.


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 91 [r1] (raw file):

    (
        [Parameter(Mandatory = $true)]
        [ValidateSet('1')]

~~I'm not sure I understand this ValidateSet what's this doing? ~~ Why are we limiting ourselves to the default SMTP? Couldn't we be managing multiple SMTP servers?


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 256 [r1] (raw file):

    #Update AuthFlags if required
    if (($PSBoundParameters.ContainsKey('AuthFlags') -and `

So just a thought here, could we possibly do a loop instead of each check individually?

You could use the following code as a basis: https://github.com/PowerShell/xNetworking/blob/dev/DSCResources/MSFT_xFirewall/MSFT_xFirewall.psm1#L41

Then we could do something like:

foreach ($parameter in $ParameterList)
{
    if ($PSBoundParameters.ContainsKey($Parameter) -and $Result.$Parameter -ne $PSBoundParameter[$Parameter]
    {
        Write-Verbose -Message "Updated SMTPSetting {0} from {1} to {2}" -f $Parameter, $Result.$Parameter, $PSBoundParameter[$Parameter]
         Set-SMTPSettings `
            -Name $Name `
            -Setting $Parameter
            -Value $PSBoundParameter[$Parameter]
    }
}

This would cover all of the setting/checking and break it down into a more "simple"* loop.

  • Obviously would require testing but it reduces the amount if checks we're writing. 😁

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 257 [r1] (raw file):

    #Update AuthFlags if required
    if (($PSBoundParameters.ContainsKey('AuthFlags') -and `
    $Result.AuthFlags -ne $AuthFlags))

Could we move this over four spaces?

if (($PSBoundParameters.ContainsKey('AuthFlags') -and `
    $Result.AuthFlags -ne $AuthFlags))
{
    #code stuff
}

Actually you can assume that I'd like to see this all the way down.


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 272 [r1] (raw file):

        {
            $ErrorMessage = $LocalizedData.ErrorBadMailDirectoryFailure
            New-TerminatingError -ErrorId 'BadMailDirectoryFailure' `

Are we being proactive or does this actually fail if the folder doesn't exist?


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 717 [r1] (raw file):

    #Update AuthFlags if required
    if (($PSBoundParameters.ContainsKey('AuthFlags') -and 
    $Result.AuthFlags -ne $AuthFlags))

Same comments for Set-TargetResource as for here as a way to tighten up the loop of things we can do.


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1009 [r1] (raw file):

Function Confirm-UnqiueBindings
{
    <#

I think the style is to have this outside of the function? Honestly I'm not sure here but you need at least four more spaces.

<#
    .SYNOPSIS
#>

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1029 [r1] (raw file):

        [String]
        $ExistingBindings,

tab I think?


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1042 [r1] (raw file):

    }

    $ExistingBindingssToCheck = $ExistingBindings -split '\n'

Think you got to many ss here. I think your variable should probably be $ExistingBindingsToCheck (note one less s)


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1050 [r1] (raw file):

    }

    $SortedExistingBindings = $ExistingToCheck | Sort-Object -Unique

Think we can just get away with doing:

$ExistingToCheck = $ExistingToCheck | Sort-Object -Unique
$InputToCheck = $InputToCheck | Sort-Object -Unique

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1124 [r1] (raw file):

Function Test-EmailAddress
{
        <#

Missalinged comment.


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1136 [r1] (raw file):

    [CmdletBinding()]
    param(

Tab?


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1143 [r1] (raw file):

    )

    if($Email)

Email is mandatory shouldn't this always be true? And if so why do we need it?


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1148 [r1] (raw file):

        {
            $ErrorMessage = $LocalizedData.ErrorEmailAddressFailure
            New-TerminatingError -ErrorId 'EmailAddressFailure' `

If our output is supposed to be a boolean why are we throwing here?

Personal preference, test- cmdlets shouldn't throw only return true/false.


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1183 [r1] (raw file):

    foreach ($Binding in $ServerBindings)

Could you remove this space here please.


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1193 [r1] (raw file):

            {
                $ErrorMessage = $LocalizedData.ErrorIPAddressFailure
                New-TerminatingError -ErrorId 'IPAddressFailure' `

Also do we need to terminate here? Could we just return false?


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1212 [r1] (raw file):

        }

        return $true

I think if you have multiple ServerBindings wouldn't this exist the function before all of them have been tested? I think you want to move your return $true outside of the foreach loop.


DSCResources/MSFT_xSMTP/MSFT_xSMTP.schema.mof, line 4 [r1] (raw file):

class MSFT_xSMTP : OMI_BaseResource
{
    [Key] UInt16 ID;

I'm not seeing $name in the schema, should this be $name and not $id?


Tests/Integration/MSFT_xSMTP.config.ps1, line 45 [r1] (raw file):

        }
    }
}

Need a new line here.


Tests/Integration/MSFT_xSMTP.config.psd1, line 5 [r1] (raw file):

    AllNodes = @(
        @{
                Name                             = '1'

Does tthis not work if we have it as:

Name = 1

That would cast it as an int instead of a string.


Tests/Integration/MSFT_xSMTP.config.psd1, line 40 [r1] (raw file):

        }
    )
}

Need a new line here.


Tests/Integration/MSFT_xSMTP.Integration.tests.ps1, line 28 [r1] (raw file):

    . $ConfigFile

    $null = Backup-WebConfiguration -Name $tempName

Could we backup the web config before loading the config file please?


Tests/Integration/MSFT_xSMTP.Integration.tests.ps1, line 47 [r1] (raw file):

        It 'Should create a WebApplication with correct settings' -test {

tab?


Tests/Integration/MSFT_xSMTP.Integration.tests.ps1, line 100 [r1] (raw file):

    Restore-TestEnvironment -TestEnvironment $TestEnvironment
    #endregion
}

New line here


Tests/Unit/MSFT_xSMTP.tests.ps1, line 14 [r1] (raw file):

Import-Module (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force
$TestEnvironment = Initialize-TestEnvironment `
-DSCModuleName $global:DSCModuleName `

Need some tabs here


Tests/Unit/MSFT_xSMTP.tests.ps1, line 24 [r1] (raw file):

{
    #region Pester Tests

tabs?


Tests/Unit/MSFT_xSMTP.tests.ps1, line 325 [r1] (raw file):

            }

            Context 'All Settings are incorrect' {

I'm not sure this is doing what you think it is. Because you are doing a return $false this would return out on the first check and be done, so it doesn't really matter that all of them are wrong it's only checking the first one. I'm not sure this is actually valuable.


Tests/Unit/MSFT_xSMTP.tests.ps1, line 347 [r1] (raw file):

                $Result = Test-TargetResource -Name $MockParamaters.Name -AuthFlags $MockParamaters.AuthFlags

                It 'should return False' {

So consider this advice for all of these. I would consider adding a check for the verbose message to validate you are hitting the line you think you are. In your code you do a return $false the first time you run into something that's wrong, which imo is good practice no sense in checking the rest of it.

This would be tested like this:

$Result = Test-TargetResource -Name $MockParamaters.Name -AuthFlags $MockParamaters.AuthFlags -Verbose 4>&1

It 'should return False' {
    $Result[0] | Should Be $false
}

It 'should return the correct message' {
   $result[1] | Should Be $LocalizedData.VerboseTestTargetFalseAuthFlags
}

Tests/Unit/MSFT_xSMTP.tests.ps1, line 817 [r1] (raw file):

            Context 'AuthFlags exists but needs to be updated' {

                Mock -CommandName Get-SMTPSettings -MockWith {

Your spacing gets all of from about here down in the code. Your closing brace should line up with Mock and all functions below it should line up as well. Might want to take a pass through this.


Tests/Unit/MSFT_xSMTP.tests.ps1, line 821 [r1] (raw file):

                        }

                    Mock -CommandName Set-SMTPSettings

I would consider adding ParameterFilter to the mock, here we're not 100% sure we've called the right thing at the right time. This would look like.

Mock Set-SMTPSettings {}
Mock -CommandName Set-SMTPSettings -ParameterFilter { $Setting -eq 'AuthFlags' -and $Value -eq $MockParameters.AuthFlags}

It 'should call the expected mocks' {
    $Result = Set-TargetResource -Name $MockParamaters.Name -AuthFlags $MockParamaters.AuthFlags

    Assert-MockCalled -CommandName Set-SMTPSettings -Exactly 0
    Assert-MockCalled -CommandName Set-SMTPSettings  -ParameterFilter { $Setting -eq 'AuthFlags' -and $Value -eq $MockParameters.AuthFlags} -Exactly 1
}

This is not only validating that you called the right function with the right call but you didn't call it some other way.


Comments from Reviewable

@nzspambot
Copy link
Author

You're the boss; whatever you want you can have


Review status: all files reviewed at latest revision, 30 unresolved discussions, some commit checks failed.


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 11 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Going to need to add four spaces to all of these or @mbreakey3 will come scowl at you.

hehe, Done.

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 91 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

~~I'm not sure I understand this ValidateSet what's this doing? ~~ Why are we limiting ourselves to the default SMTP? Couldn't we be managing multiple SMTP servers?

Done. That was me flip flopping back and forth

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 256 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

So just a thought here, could we possibly do a loop instead of each check individually?

You could use the following code as a basis: https://github.com/PowerShell/xNetworking/blob/dev/DSCResources/MSFT_xFirewall/MSFT_xFirewall.psm1#L41

Then we could do something like:

foreach ($parameter in $ParameterList)
{
    if ($PSBoundParameters.ContainsKey($Parameter) -and $Result.$Parameter -ne $PSBoundParameter[$Parameter]
    {
        Write-Verbose -Message "Updated SMTPSetting {0} from {1} to {2}" -f $Parameter, $Result.$Parameter, $PSBoundParameter[$Parameter]
         Set-SMTPSettings `
            -Name $Name `
            -Setting $Parameter
            -Value $PSBoundParameter[$Parameter]
    }
}

This would cover all of the setting/checking and break it down into a more "simple"* loop.

  • Obviously would require testing but it reduces the amount if checks we're writing. 😁
Looks much nicer IMO, I really didn't like the massive stack of repeating code. Let me refactor it then.

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 257 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Could we move this over four spaces?

if (($PSBoundParameters.ContainsKey('AuthFlags') -and `
    $Result.AuthFlags -ne $AuthFlags))
{
    #code stuff
}

Actually you can assume that I'd like to see this all the way down.

Done.

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 272 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Are we being proactive or does this actually fail if the folder doesn't exist?

It will fail to start if the folder doesn't exist yes.

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1009 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

I think the style is to have this outside of the function? Honestly I'm not sure here but you need at least four more spaces.

<#
    .SYNOPSIS
#>
I will wait to hear brack from Maria

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1029 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

tab I think?

no those are spaces

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1042 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Think you got to many ss here. I think your variable should probably be $ExistingBindingsToCheck (note one less s)

Done.

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1050 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Think we can just get away with doing:

$ExistingToCheck = $ExistingToCheck | Sort-Object -Unique
$InputToCheck = $InputToCheck | Sort-Object -Unique
no and the compare will fail as I found during testing

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1124 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Missalinged comment.

Done.

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1136 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Tab?

no just badly formatted param blocks

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1143 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Email is mandatory shouldn't this always be true? And if so why do we need it?

if email is ok then this will work; this just checks the email is ok

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1148 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

If our output is supposed to be a boolean why are we throwing here?

Personal preference, test- cmdlets shouldn't throw only return true/false.

because I want to return to the user any issues, helps troubleshooting. Returning a false hides errors

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1183 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Could you remove this space here please.

Done.

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1193 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Also do we need to terminate here? Could we just return false?

because I want to return to the user any issues, helps troubleshooting. Returning a false hides errors

DSCResources/MSFT_xSMTP/MSFT_xSMTP.schema.mof, line 4 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

I'm not seeing $name in the schema, should this be $name and not $id?

yeah I seem to have forgotten to grab the copy from my dev machine so this commit is stale; next commit will be correct(or)

Tests/Integration/MSFT_xSMTP.config.ps1, line 45 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Need a new line here.

Done.

Tests/Integration/MSFT_xSMTP.config.psd1, line 5 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Does tthis not work if we have it as:

Name = 1

That would cast it as an int instead of a string.

nope, default is [string] so this will be a string

Tests/Integration/MSFT_xSMTP.config.psd1, line 40 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Need a new line here.

Done.

Tests/Integration/MSFT_xSMTP.Integration.tests.ps1, line 28 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Could we backup the web config before loading the config file please?

Done.

Tests/Integration/MSFT_xSMTP.Integration.tests.ps1, line 47 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

tab?

Done.

Tests/Integration/MSFT_xSMTP.Integration.tests.ps1, line 100 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

New line here

Done.

Tests/Unit/MSFT_xSMTP.tests.ps1, line 14 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Need some tabs here

Done.

Tests/Unit/MSFT_xSMTP.tests.ps1, line 24 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

tabs?

Done.

Tests/Unit/MSFT_xSMTP.tests.ps1, line 325 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

I'm not sure this is doing what you think it is. Because you are doing a return $false this would return out on the first check and be done, so it doesn't really matter that all of them are wrong it's only checking the first one. I'm not sure this is actually valuable.

I think it is ok as if your mock params are wrong this will flag it. Its neither here nor there I guess

Tests/Unit/MSFT_xSMTP.tests.ps1, line 347 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

So consider this advice for all of these. I would consider adding a check for the verbose message to validate you are hitting the line you think you are. In your code you do a return $false the first time you run into something that's wrong, which imo is good practice no sense in checking the rest of it.

This would be tested like this:

$Result = Test-TargetResource -Name $MockParamaters.Name -AuthFlags $MockParamaters.AuthFlags -Verbose 4>&1

It 'should return False' {
    $Result[0] | Should Be $false
}

It 'should return the correct message' {
   $result[1] | Should Be $LocalizedData.VerboseTestTargetFalseAuthFlags
}
I like; very good point

Tests/Unit/MSFT_xSMTP.tests.ps1, line 821 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

I would consider adding ParameterFilter to the mock, here we're not 100% sure we've called the right thing at the right time. This would look like.

Mock Set-SMTPSettings {}
Mock -CommandName Set-SMTPSettings -ParameterFilter { $Setting -eq 'AuthFlags' -and $Value -eq $MockParameters.AuthFlags}

It 'should call the expected mocks' {
    $Result = Set-TargetResource -Name $MockParamaters.Name -AuthFlags $MockParamaters.AuthFlags

    Assert-MockCalled -CommandName Set-SMTPSettings -Exactly 0
    Assert-MockCalled -CommandName Set-SMTPSettings  -ParameterFilter { $Setting -eq 'AuthFlags' -and $Value -eq $MockParameters.AuthFlags} -Exactly 1
}

This is not only validating that you called the right function with the right call but you didn't call it some other way.

Good point

Comments from Reviewable

@nzspambot
Copy link
Author

@tysonjhayes made some changes based on your review but I am not in position to test them right now sorry so expect them to not work and fail

@tysonjhayes
Copy link

Review status: 1 of 7 files reviewed at latest revision, 9 unresolved discussions, some commit checks failed.


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 272 [r1] (raw file):

Previously, nzspambot (James Baker) wrote…

It will fail to start if the folder doesn't exist yes.

Is the error message unclear when it tries to set it or is there a value in us failing it out? Personally I'm not a fan of doing much error handling preferring to push it down as low as I can. If the error message is unclear as to whats happen I'm totally a fan of adding this.

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1029 [r1] (raw file):

Previously, nzspambot (James Baker) wrote…

no those are spaces

Yeah I'll stop point it out.

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1143 [r1] (raw file):

Previously, nzspambot (James Baker) wrote…

if email is ok then this will work; this just checks the email is ok

I'm not sure I'm being clear here. We have to specifiy a value for $Email, you appear to be testing that there is a value for $Email before evaluating if $Email is formatted as a mailing address. I don't think we need to check if $Email has a value because if it is null it wouldn't pass the next check.

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1148 [r1] (raw file):

Previously, nzspambot (James Baker) wrote…

because I want to return to the user any issues, helps troubleshooting. Returning a false hides errors

Then I would say this should return false and we capture the error outside of the function. So that'd be like:
if (Test-EmailAddress -EmailAddress 'Notagoodemail.com')
{
    # do whatever
}
else
{
    # throw terminatingerror here
}

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1193 [r1] (raw file):

Previously, nzspambot (James Baker) wrote…

because I want to return to the user any issues, helps troubleshooting. Returning a false hides errors

See my notes on test-emailaddress

Tests/Integration/MSFT_xSMTP.config.psd1, line 5 [r1] (raw file):

Previously, nzspambot (James Baker) wrote…

nope, default is [string] so this will be a string

I guess why is it a string versus an int then? You mentioned something about it being 💩 for the integration tests but I wasn't really following what was going on. Could you help me understand?

Comments from Reviewable

@tysonjhayes
Copy link

Reviewed 5 of 6 files at r2, 1 of 1 files at r3.
Review status: all files reviewed at latest revision, 9 unresolved discussions, some commit checks failed.


Comments from Reviewable

@nzspambot
Copy link
Author

Review status: all files reviewed at latest revision, 9 unresolved discussions, some commit checks failed.


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 272 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Is the error message unclear when it tries to set it or is there a value in us failing it out? Personally I'm not a fan of doing much error handling preferring to push it down as low as I can. If the error message is unclear as to whats happen I'm totally a fan of adding this.

Well in testing you can set anything you like but if you then go into the console it will fail to start an you will only (I think) find out it is a directory issue once you hit the correct page in the settings

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1029 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Yeah I'll stop point it out.

It's fine; I am thinking I will add something to the DSCResource tests/PSSA to handle this to keep everyone happy

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1143 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

I'm not sure I'm being clear here. We have to specifiy a value for $Email, you appear to be testing that there is a value for $Email before evaluating if $Email is formatted as a mailing address. I don't think we need to check if $Email has a value because if it is null it wouldn't pass the next check.

I'm a bit lost here. If there is no email in the Test then yes it will never test it. If there is an email then we test that the email is valid . Thats what I was aiming for

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1148 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Then I would say this should return false and we capture the error outside of the function. So that'd be like:

if (Test-EmailAddress -EmailAddress 'Notagoodemail.com')
{
    # do whatever
}
else
{
    # throw terminatingerror here
}
If you want that then you could do away with the test function and cast -as in the if{} then

I personally like the idea of subfunctions which are $true/$false and error


Tests/Integration/MSFT_xSMTP.config.psd1, line 5 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

I guess why is it a string versus an int then? You mentioned something about it being 💩 for the integration tests but I wasn't really following what was going on. Could you help me understand?

Yeah so in testing DSC is applied correctly however if you run a Get-DSCConfiguration that will bomb out. Digging through it is because the [ASDI] params are a (OTTOMH) a dictionary type which would not cast to [int] would only cast to [string]

Comments from Reviewable

@tysonjhayes
Copy link

Review status: 5 of 7 files reviewed at latest revision, 8 unresolved discussions, some commit checks failed.


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 272 [r1] (raw file):

Previously, nzspambot (James Baker) wrote…

Well in testing you can set anything you like but if you then go into the console it will fail to start an you will only (I think) find out it is a directory issue once you hit the correct page in the settings

I guess I'm asking if you specifiy a bad directory without this test path what happens? What error messages does it give you, if any? If it has none then yeah let's have this throw something, else lets evaluate what its saying to see if we're adding value.

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1143 [r1] (raw file):

Previously, nzspambot (James Baker) wrote…

I'm a bit lost here. If there is no email in the Test then yes it will never test it. If there is an email then we test that the email is valid
. Thats what I was aiming for

Basically checking if $Email has a value doesn't seem valuable to me, and I guess I'm recommending we remove it. If you want to make sure it has a value I would add some parameter validation.

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1148 [r1] (raw file):

Previously, nzspambot (James Baker) wrote…

If you want that then you could do away with the test function and cast -as in the if{} then

I personally like the idea of subfunctions which are $true/$false and error

Personally I write my code like that. This just seems like we're adding more layers where there doesn't really need to be, just my thoughts though.

Tests/Integration/MSFT_xSMTP.config.psd1, line 5 [r1] (raw file):

Previously, nzspambot (James Baker) wrote…

Yeah so in testing DSC is applied correctly however if you run a Get-DSCConfiguration that will bomb out. Digging through it is because the [ASDI] params are a (OTTOMH) a dictionary type which would not cast to [int] would only cast to [string]

That makes perfect sense. Could we make a note... somewhere? Maybe in the mof file or something so we don't try to "correct" this?

Comments from Reviewable

@tysonjhayes
Copy link

Reviewed 2 of 2 files at r4.
Review status: all files reviewed at latest revision, 9 unresolved discussions, some commit checks failed.


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 359 [r4] (raw file):

                    <#
                     Bug?
                     Blank to since name does not need to be set

You can remove the parameter and make a note saying we don't need to specify it. I'd do this before the loop.

https://clan8blog.wordpress.com/2014/06/26/removing-a-parameter-from-psboundparameters/


Comments from Reviewable

@nzspambot
Copy link
Author

Review status: all files reviewed at latest revision, 9 unresolved discussions, some commit checks failed.


DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 272 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

I guess I'm asking if you specifiy a bad directory without this test path what happens? What error messages does it give you, if any? If it has none then yeah let's have this throw something, else lets evaluate what its saying to see if we're adding value.

Nothing, value is accepted but the SMTP server will stop

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1143 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Basically checking if $Email has a value doesn't seem valuable to me, and I guess I'm recommending we remove it. If you want to make sure it has a value I would add some parameter validation.

No, I'm checking that $email is valid if present (well that was the aim) TBH I don't need to do this but I was trying to be helpful

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 1148 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

Personally I write my code like that. This just seems like we're adding more layers where there doesn't really need to be, just my thoughts though.

I know, I value your feedback

DSCResources/MSFT_xSMTP/MSFT_xSMTP.psm1, line 359 [r4] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

You can remove the parameter and make a note saying we don't need to specify it. I'd do this before the loop.

https://clan8blog.wordpress.com/2014/06/26/removing-a-parameter-from-psboundparameters/

Yeah that's the conclusion I came to today

Tests/Integration/MSFT_xSMTP.config.psd1, line 5 [r1] (raw file):

Previously, tysonjhayes (Tyson J. Hayes) wrote…

That makes perfect sense. Could we make a note... somewhere? Maybe in the mof file or something so we don't try to "correct" this?

Sure, can do something somewhere

Comments from Reviewable

@tysonjhayes
Copy link

Reviewed 4 of 4 files at r5.
Review status: all files reviewed at latest revision, 4 unresolved discussions, some commit checks failed.


Comments from Reviewable

@nzspambot
Copy link
Author

@tysonjhayes I want to come back to this but I feel like this is going to go nowhere fast due to the issues I encountered

@kwirkykat kwirkykat added the waiting for author response The pull request is waiting for the author to respond to comments in the pull request. label Aug 19, 2016
@eshaparmar
Copy link

@nzspambot are you still planning to work on this? or can we close this pr?

@nzspambot
Copy link
Author

@eshaparmar I would like to get back at looking at this but won't be anytime soon so yeah I will close this for now

@nzspambot nzspambot closed this Oct 4, 2016
@vors vors removed the waiting for author response The pull request is waiting for the author to respond to comments in the pull request. label Oct 4, 2016
@johlju
Copy link
Member

johlju commented Apr 25, 2018

As this is part of an open issue, I will reopen this I leave it as abandoned so someone else can continue the work.

@johlju johlju reopened this Apr 25, 2018
@johlju johlju added the abandoned The pull request has been abandoned. label Apr 25, 2018
@nzspambot nzspambot closed this Feb 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
abandoned The pull request has been abandoned.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants