Skip to content

Revert On-Prmeise encryption back #284

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

Merged
merged 3 commits into from
Mar 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScenarioTests\DataFactoriesScenarioTestsBase.cs" />
<Compile Include="ScenarioTests\DataFactoryTests.cs" />
<Compile Include="UnitTests\NewDataFactoryEncryptValueTests.cs" />
<Compile Include="UnitTests\NewDataFactoryGatewayKeyTests.cs" />
<Compile Include="UnitTests\NewDataFactoryGatewayTests.cs" />
<Compile Include="UnitTests\NewLinkedServiceTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.DataFactories;
using Microsoft.Azure.Commands.DataFactories.Test;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Moq;
using System;
using System.Management.Automation;
using System.Security;
using Xunit;

namespace Microsoft.WindowsAzure.Commands.Test.DataFactory
{
public class NewDataFactoryEncryptValueTests : DataFactoryUnitTestBase
{
public NewDataFactoryEncryptValueTests()
{
base.SetupTest();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestOnPremDatasourceEncryptionSQLAuth()
{
SecureString secureString = new SecureString();
string expectedOutput = "My encrypted string " + Guid.NewGuid();
string linkedServiceType = "OnPremisesSqlLinkedService";

var cmdlet = new NewAzureDataFactoryEncryptValueCommand
{
CommandRuntime = this.commandRuntimeMock.Object,
DataFactoryClient = this.dataFactoriesClientMock.Object,
Value = secureString,
ResourceGroupName = ResourceGroupName,
DataFactoryName = DataFactoryName,
GatewayName = GatewayName,
Type = linkedServiceType
};

// Arrange
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, linkedServiceType)).Returns(expectedOutput);

// Action
cmdlet.ExecuteCmdlet();

// Assert
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, linkedServiceType), Times.Once());
this.commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestOnPremDatasourceEncryptionWinAuth()
{
SecureString secureString = new SecureString();
string expectedOutput = "My encrypted string " + Guid.NewGuid();
string winAuthUserName = "foo";
SecureString winAuthPassword = new SecureString();
PSCredential credential = new PSCredential(winAuthUserName, winAuthPassword);
string linkedServiceType = "OnPremisesFileSystemLinkedService";

var cmdlet = new NewAzureDataFactoryEncryptValueCommand
{
CommandRuntime = this.commandRuntimeMock.Object,
DataFactoryClient = this.dataFactoriesClientMock.Object,
Value = secureString,
ResourceGroupName = ResourceGroupName,
DataFactoryName = DataFactoryName,
GatewayName = GatewayName,
Credential = credential,
Type = linkedServiceType
};

// Arrange
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential, linkedServiceType)).Returns(expectedOutput);

// Action
cmdlet.ExecuteCmdlet();

// Assert
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential, linkedServiceType), Times.Once());
this.commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
<Compile Include="DataSlices\GetAzureDataFactorySliceCommand.cs" />
<Compile Include="DataSlices\SaveAzureDataFactoryLog.cs" />
<Compile Include="DataSlices\SetAzureDataFactorySliceStatusCommand.cs" />
<Compile Include="Encrypt\NewAzureDataFactoryEncryptValueCommand.cs" />
<Compile Include="Gateway\GetAzureDataFactoryGatewayCommand.cs" />
<Compile Include="Gateway\NewAzureDataFactoryGatewayCommand.cs" />
<Compile Include="Gateway\NewAzureDataFactoryGatewayKeyCommand.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ internal static class Constants

public const string GatewayKey = "AzureDataFactoryGatewayKey";

public const string EncryptString = "AzureDataFactoryEncryptValue";

public const string Table = "AzureDataFactoryTable";

public const string Pipeline = "AzureDataFactoryPipeline";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Globalization;
using System.Management.Automation;
using System.Security;
using System.Security.Permissions;
using Microsoft.Azure.Commands.DataFactories.Models;
using Microsoft.Azure.Commands.DataFactories.Properties;

namespace Microsoft.Azure.Commands.DataFactories
{
[Cmdlet(VerbsCommon.New, Constants.EncryptString, DefaultParameterSetName = ByFactoryName), OutputType(typeof(string))]
public class NewAzureDataFactoryEncryptValueCommand : DataFactoryBaseCmdlet
{
[Parameter(ParameterSetName = ByFactoryObject, Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true,
HelpMessage = "The data factory object.")]
public PSDataFactory DataFactory { get; set; }

[Parameter(ParameterSetName = ByFactoryName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true,
HelpMessage = "The data factory name.")]
[ValidateNotNullOrEmpty]
public string DataFactoryName { get; set; }

[Parameter(ParameterSetName = ByFactoryObject, Position = 1, Mandatory = true, HelpMessage = "The value to encrypt.")]
[Parameter(ParameterSetName = ByFactoryName, Position = 2, Mandatory = true, HelpMessage = "The value to encrypt.")]
[ValidateNotNullOrEmpty]
public SecureString Value { get; set; }

[Parameter(ParameterSetName = ByFactoryObject, Position = 2, Mandatory = false, HelpMessage = "The gateway group name.")]
[Parameter(ParameterSetName = ByFactoryName, Position = 3, Mandatory = false, HelpMessage = "The gateway group name.")]
public string GatewayName { get; set; }

[Parameter(ParameterSetName = ByFactoryObject, Position = 3, Mandatory = false, HelpMessage = "The windows authentication credential.")]
[Parameter(ParameterSetName = ByFactoryName, Position = 4, Mandatory = false, HelpMessage = "The windows authentication credential.")]
public PSCredential Credential { get; set; }

[Parameter(ParameterSetName = ByFactoryObject, Position = 4, Mandatory = false, HelpMessage = "The linked service type.")]
[Parameter(ParameterSetName = ByFactoryName, Position = 5, Mandatory = false, HelpMessage = "The linked service type.")]
[ValidateSet("OnPremisesSqlLinkedService", "OnPremisesFileSystemLinkedService", "OnPremisesOracleLinkedService", IgnoreCase = true)]
public string Type { get; set; }

[EnvironmentPermission(SecurityAction.Demand, Unrestricted = true)]
public override void ExecuteCmdlet()
{
if (ParameterSetName == ByFactoryObject)
{
if (DataFactory == null)
{
throw new PSArgumentNullException(string.Format(CultureInfo.InvariantCulture,
Resources.DataFactoryArgumentInvalid));
}

DataFactoryName = DataFactory.DataFactoryName;
ResourceGroupName = DataFactory.ResourceGroupName;
}

string encryptedValue = String.Empty;

if (String.IsNullOrWhiteSpace(GatewayName))
{
// Cloud encryption without Gateway
WriteWarning("Cloud encryption has already been deprecated. Please run get-help new-azuredatafactoryencryptvalue to see other option of this command");
}
else
{
// On-premises encryption with Gateway
encryptedValue = DataFactoryClient.OnPremisesEncryptString(Value, ResourceGroupName, DataFactoryName, GatewayName, Credential, Type);
}

WriteObject(encryptedValue);
}
}
}
Loading