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

Integration tests fails with SecurityException: Security error #38

Closed
johlju opened this issue Dec 27, 2019 · 6 comments · Fixed by #39
Closed

Integration tests fails with SecurityException: Security error #38

johlju opened this issue Dec 27, 2019 · 6 comments · Fixed by #39
Labels
bug The issue is a bug.

Comments

@johlju
Copy link
Member

johlju commented Dec 27, 2019

When Restore-TestEnvironment is called at the end of an integration tests it fails with the error in Azure DevOps.

2019-12-27T10:17:05.5277355Z   [-] Error occurred in test script 'D:\a\1\s\tests\Integration\MSFT_WebApplicationHandler.Integration.Tests.ps1' 0ms
2019-12-27T10:17:05.5277528Z     SecurityException: Security error.
2019-12-27T10:17:05.5277606Z     at Restore-TestEnvironment, D:\a\1\s\output\RequiredModules\DscResource.Test\0.8.0\DscResource.Test.psm1: line 1628

The line this happens on is

    if ($script:MachineOldExecutionPolicy)
    {
        Set-ExecutionPolicy -ExecutionPolicy $script:MachineOldExecutionPolicy -Scope LocalMachine -Force -ErrorAction Stop
    }
@johlju
Copy link
Member Author

johlju commented Dec 27, 2019

In the build worker in Azure DevOps (2016 image) the execution policy for the machine is 'RemoteSigned' which is changed to 'Unrestricted' when Initialize-TestEnvironment. So apparently there are an issue reverting the execution policy when Restore-TestEnvironment is called.

@gaelcolas
Copy link
Member

Have you tried an integration tests that does nothing besides Initialize and Restore?
I think it may not be an issue with the Execution Policy, but with the fact that the environment has changed if you kicked off some DSC config locally, conflicting with setting the Execution Policy back... (config precedence, current user changes in privileges...)

Getting the full error message of the issue would be best, as it should tell you if the SecurityException is because of Access Denied (account changes) or precedence (change in local policy? or other scope)

@johlju
Copy link
Member Author

johlju commented Dec 27, 2019

How do we get the full error message?

I am not running integration tests locally.

@gaelcolas
Copy link
Member

In this case you could try a Set-ExecutionPolicy directly, outside the Describe block at the end (after removing the failing Restore-TestEnvironment).
It should still fail but giving you more details about the error (because it's not wrapped within pester).

@johlju
Copy link
Member Author

johlju commented Dec 27, 2019

But the Restore-TestEnvironment function is already running outside of any Describe-block.

@johlju
Copy link
Member Author

johlju commented Dec 27, 2019

I fixed the integration test in PR #39 to be a simpler one but still generates the error if the code in PR #39 is not used. So that we have a regression test.

@johlju johlju added bug The issue is a bug. in progress The issue is being actively worked on by someone. labels Dec 27, 2019
@johlju johlju removed the in progress The issue is being actively worked on by someone. label Aug 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants