Reputation: 45
I am writing integration tests for our code connecting to a Thycotic Secret Server. For security reasons, the password for the Thycotic server is encrypted when stored in the appsetting.json
file. The encryption key is to be stored in a System Level environment variable. In addition, security policy says that the encrypted password and encryption key can never be stored in the same place. The encrypted password can be in the code, but the encryption key must not be. Their recommendation is to store it as a System level environment variable. This arrangement has been implemented by our corporate IT Security team, and is not something I can alter.
Right now I am trying to write integration tests for this process. I am running into issues accessing the system level environment variables from inside the test fixtures. Environment.GetEnvironmentVariable
returns null. The only thing that has worked so far, is using Environment.SetEnvironmentVariable(Name, Value)
from inside the test class. Unfortunately, this puts both the encryption key, and encrypted password in code, which violates the policy.
I've searched Stack Overflow and Google to find a solution for this, but everything points to using Environment.SetEnvironmentVariable
in the code, and since that isn't something I can do, I'm stuck.
Does anyone know a way I can access the System level environment variable inside an MSTest text fixture on .NET Core? Is there some resource I missed in my Google search?
Upvotes: 2
Views: 262
Reputation: 45
I was missing the fact that when creating a new Windows System Environment Variable, that Visual Studio needs to be restarted to see the addition/change. This is no longer an issue.
Upvotes: 1