Skip to content
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 @@ -97,7 +97,7 @@ await CommandTestBuilder.CreateAsync<RunScriptCommand, Program>()
.WithArrange(context =>
{
AddDefaults(context);
context.Variables.Add(SpecialVariables.Action.Azure.Environment, "NotARealAzureEnvironment");
context.Variables.Set(SpecialVariables.Action.Azure.Environment, "NotARealAzureEnvironment");
context.Variables.Add(PowerShellVariables.Edition, ScriptVariables.ScriptSourceOptions.Core);
context.Variables.Add(ScriptVariables.ScriptSource, ScriptVariables.ScriptSourceOptions.Inline);
context.Variables.Add(ScriptVariables.Syntax, ScriptSyntax.PowerShell.ToString());
Expand All @@ -108,6 +108,7 @@ await CommandTestBuilder.CreateAsync<RunScriptCommand, Program>()

void AddDefaults(CommandTestBuilderContext context)
{
context.Variables.Add(SpecialVariables.Action.Azure.Environment, "AzureCloud");
context.Variables.Add(SpecialVariables.Account.AccountType, "AzureServicePrincipal");
context.Variables.Add(SpecialVariables.Action.Azure.SubscriptionId, subscriptionId);
context.Variables.Add(SpecialVariables.Action.Azure.TenantId, tenantId);
Expand All @@ -117,4 +118,4 @@ void AddDefaults(CommandTestBuilderContext context)
context.WithTool(AzureCmdlets);
}
}
}
}
22 changes: 18 additions & 4 deletions source/Calamari.Testing/EnvironmentVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,29 @@ public enum ExternalVariable
[EnvironmentVariable("K8S_OctopusAPITester_Server", "op://Calamari Secrets for Tests/GKS Kubernetes API Test Cluster/Server")]
KubernetesClusterUrl,

[EnvironmentVariable("Helm_OctopusAPITester_Url", "op://Calamari Secrets for Tests/Artifactory e2e-reader Test Account/url")]
ArtifactoryUrl,

[EnvironmentVariable("Helm_OctopusAPITester_Url", "op://Calamari Secrets for Tests/Artifactory e2e-reader Test Account/docker-url")]
ArtifactoryDockerUrl,

[EnvironmentVariable("Helm_OctopusAPITester_Username", "op://Calamari Secrets for Tests/Artifactory e2e-reader Test Account/username")]
ArtifactoryUsername,

[EnvironmentVariable("Helm_OctopusAPITester_Password", "op://Calamari Secrets for Tests/Artifactory e2e-reader Test Account/password")]
HelmPassword,
ArtifactoryPassword,

[EnvironmentVariable("Artifactory_Admin_PAT", "op://Calamari Secrets for Tests/Artifactory Admin PAT/PAT")]
ArtifactoryE2EPassword,
ArtifactoryAdminToken,

[EnvironmentVariable("DockerHub_TestReaderAccount_Url", "op://Calamari Secrets for Tests/DockerHub Test Reader Org Access Token/Url", "https://index.docker.io/v1/")]
DockerHubOrgAccessUrl,

[EnvironmentVariable("DockerHub_TestReaderAccount_Password", "op://Calamari Secrets for Tests/DockerHub Test Reader Account/password")]
DockerReaderPassword,
[EnvironmentVariable("DockerHub_TestReaderAccount_Username", "op://Calamari Secrets for Tests/DockerHub Test Reader Org Access Token/Token Username")]
DockerHubOrgAccessUsername,

[EnvironmentVariable("DockerHub_TestReaderAccount_Token", "op://Calamari Secrets for Tests/DockerHub Test Reader Org Access Token/API Token")]
DockerHubOrgAccessToken,
[EnvironmentVariable("AWS_E2E_AccessKeyId", "op://Calamari Secrets for Tests/AWS E2E Test User Keys/AccessKeyId")]
AwsCloudFormationAndS3AccessKey,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public async Task Setup()
cacheDirectory = Path.Combine(currentDirectory, testDirectory);
fileSystem.EnsureDirectoryExists(cacheDirectory);

feedUri = new Uri("https://octopusdeploy.jfrog.io");
var sensitiveValue = await ExternalVariables.Get(ExternalVariable.ArtifactoryE2EPassword, cancellationToken);
var authFeedUri = await ExternalVariables.Get(ExternalVariable.ArtifactoryUrl, cancellationToken);
feedUri = new Uri(authFeedUri);
var sensitiveValue = await ExternalVariables.Get(ExternalVariable.ArtifactoryAdminToken, cancellationToken);
feedCredentials = new NetworkCredential("", sensitiveValue.ToString());

var log = Substitute.For<ILog>();
Expand Down Expand Up @@ -125,4 +126,4 @@ public void Downloads_AcmeWeb_TarGz()
packagePhysicalFile.Hash.Should().Be("0b58492e7eef21639e77b0f2b5137bbe3c377c6e");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,24 @@ namespace Calamari.Tests.Fixtures.Integration.Packages
[TestFixture]
public class DockerImagePackageDownloaderFixture
{
static readonly string AuthFeedUri = "https://octopusdeploy-docker.jfrog.io";
static readonly string FeedUsername = "e2e-reader";
static string FeedPassword;
static readonly string Home = Path.GetTempPath();

static readonly string DockerHubFeedUri = "https://index.docker.io";
static readonly string DockerTestUsername = "octopustestaccount";
static string DockerTestPassword;
string authFeedUri;
string feedUsername;
string feedPassword;
string dockerHubFeedUri;
string dockerTestUsername;
string dockerTestPassword;
static readonly CancellationTokenSource CancellationTokenSource = new CancellationTokenSource();
readonly CancellationToken cancellationToken = CancellationTokenSource.Token;

[OneTimeSetUp]
public async Task TestFixtureSetUp()
{
FeedPassword = await ExternalVariables.Get(ExternalVariable.HelmPassword, cancellationToken);
DockerTestPassword = await ExternalVariables.Get(ExternalVariable.DockerReaderPassword, cancellationToken);
Environment.SetEnvironmentVariable("TentacleHome", Home);
authFeedUri = await ExternalVariables.Get(ExternalVariable.ArtifactoryDockerUrl, cancellationToken);
feedUsername = await ExternalVariables.Get(ExternalVariable.ArtifactoryUsername, cancellationToken);
feedPassword = await ExternalVariables.Get(ExternalVariable.ArtifactoryPassword, cancellationToken);
dockerHubFeedUri = await ExternalVariables.Get(ExternalVariable.DockerHubOrgAccessUrl, cancellationToken);
dockerTestUsername = await ExternalVariables.Get(ExternalVariable.DockerHubOrgAccessUsername, cancellationToken);
dockerTestPassword = await ExternalVariables.Get(ExternalVariable.DockerHubOrgAccessToken, cancellationToken);
}

[OneTimeTearDown]
Expand All @@ -56,7 +57,7 @@ public void PackageWithoutCredentials_Loads()
var downloader = GetDownloader();
var pkg = downloader.DownloadPackage("alpine",
new SemanticVersion("3.6.5"), "docker-feed",
new Uri(DockerHubFeedUri), null, null, true, 1,
new Uri(dockerHubFeedUri), null, null, true, 1,
TimeSpan.FromSeconds(3));

Assert.AreEqual("alpine", pkg.PackageId);
Expand All @@ -75,8 +76,9 @@ public void DockerHubWithCredentials_Loads()
var pkg = downloader.DownloadPackage(privateImage,
version,
"docker-feed",
new Uri(DockerHubFeedUri),
DockerTestUsername, DockerTestPassword,
new Uri(dockerHubFeedUri),
dockerTestUsername,
dockerTestPassword,
true,
1,
TimeSpan.FromSeconds(3));
Expand All @@ -94,8 +96,8 @@ public void PackageWithCredentials_Loads()
var pkg = downloader.DownloadPackage("octopus-echo",
new SemanticVersion("1.1"),
"docker-feed",
new Uri(AuthFeedUri),
FeedUsername, FeedPassword,
new Uri(authFeedUri),
feedUsername,feedPassword,
true, 1,
TimeSpan.FromSeconds(3));

Expand All @@ -113,7 +115,7 @@ public void PackageWithWrongCredentials_FailsWithRetry()

var exception = Assert.Throws<CommandException>(() => downloader.DownloadPackage("octopus-echo",
new SemanticVersion("1.1"), "docker-feed",
new Uri(AuthFeedUri),
new Uri(authFeedUri),
"Nonexistantuser", "SuperDooper",
true,
//we don't want to perform too many of these otherwise jfrog / artifactory gets sad at us
Expand All @@ -134,16 +136,16 @@ public void PackageWithWrongCredentials_FailsWithRetry()
[TestCase("alpine", "3.6.5")]
public void CachedDockerHubPackage_DoesNotGenerateImageNotCachedMessage(string image, string tag)
{
PreCacheImage(image, tag, DockerHubFeedUri, DockerTestUsername, DockerTestPassword);
PreCacheImage(image, tag, dockerHubFeedUri, dockerTestUsername, dockerTestPassword);

var log = new InMemoryLog();
var downloader = GetDownloader(log);
downloader.DownloadPackage(image,
new SemanticVersion(tag),
"docker-feed",
new Uri(DockerHubFeedUri),
DockerTestUsername,
DockerTestPassword,
new Uri(dockerHubFeedUri),
dockerTestUsername,
dockerTestPassword,
true,
1,
TimeSpan.FromSeconds(3));
Expand All @@ -160,14 +162,14 @@ public void CachedNonDockerHubPackage_DoesNotGenerateImageNotCachedMessage()
var log = new InMemoryLog();
var downloader = GetDownloader(log);

PreCacheImage(image, tag, AuthFeedUri, FeedUsername, FeedPassword);
PreCacheImage(image, tag, authFeedUri, feedUsername, feedPassword);

downloader.DownloadPackage(image,
new SemanticVersion(tag),
"docker-feed",
new Uri(AuthFeedUri),
FeedUsername,
FeedPassword,
new Uri(authFeedUri),
feedUsername,
feedPassword,
true,
1,
TimeSpan.FromSeconds(3));
Expand All @@ -189,9 +191,9 @@ public void NotCachedDockerHubPackage_GeneratesImageNotCachedMessage(string imag
downloader.DownloadPackage(image,
new SemanticVersion(tag),
"docker-feed",
new Uri(DockerHubFeedUri),
DockerTestUsername,
DockerTestPassword,
new Uri(dockerHubFeedUri),
dockerTestUsername,
dockerTestPassword,
true,
1,
TimeSpan.FromSeconds(3));
Expand All @@ -205,7 +207,7 @@ public void NotCachedNonDockerHubPackage_GeneratesImageNotCachedMessage()
{
const string image = "octopus-echo";
const string tag = "1.1";
var feed = new Uri(AuthFeedUri);
var feed = new Uri(authFeedUri);
var imageFullName = $"{feed.Authority}/{image}";
var log = new InMemoryLog();
var downloader = GetDownloader(log);
Expand All @@ -216,8 +218,8 @@ public void NotCachedNonDockerHubPackage_GeneratesImageNotCachedMessage()
new SemanticVersion(tag),
"docker-feed",
feed,
FeedUsername,
FeedPassword,
feedUsername,
feedPassword,
true,
1,
TimeSpan.FromSeconds(3));
Expand Down Expand Up @@ -259,4 +261,4 @@ static DockerImagePackageDownloader GetDownloader(ILog log)
return new DockerImagePackageDownloader(new ScriptEngine(Enumerable.Empty<IScriptWrapper>(), log), CalamariPhysicalFileSystem.GetPhysicalFileSystem(), runner, new CalamariVariables(), log, new FeedLoginDetailsProviderFactory());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ namespace Calamari.Tests.Fixtures.Integration.Packages
[TestFixture]
public class HelmChartPackageDownloaderFixture
{
static readonly string AuthFeedUri = "https://octopusdeploy.jfrog.io/octopusdeploy/helm-testing/";
static readonly string FeedUsername = "e2e-reader";
static string FeedPassword;
static string authFeedUri;
static string feedUsername;
static string feedPassword;
static string home = Path.GetTempPath();
HelmChartPackageDownloader downloader;
static readonly CancellationTokenSource CancellationTokenSource = new CancellationTokenSource();
Expand All @@ -28,7 +28,10 @@ public class HelmChartPackageDownloaderFixture
[OneTimeSetUp]
public async Task TestFixtureSetUp()
{
FeedPassword = await ExternalVariables.Get(ExternalVariable.HelmPassword, cancellationToken);
var baseUrl = await ExternalVariables.Get(ExternalVariable.ArtifactoryUrl, cancellationToken);
authFeedUri = $"{baseUrl}/octopusdeploy/helm-testing/";
feedUsername = await ExternalVariables.Get(ExternalVariable.ArtifactoryUsername, cancellationToken);
feedPassword = await ExternalVariables.Get(ExternalVariable.ArtifactoryPassword, cancellationToken);
Environment.SetEnvironmentVariable("TentacleHome", home);
}

Expand All @@ -47,19 +50,20 @@ public void Setup()
[Test]
public void PackageWithCredentials_Loads()
{
var pkg = downloader.DownloadPackage("mychart", new SemanticVersion("0.3.7"), "helm-feed", new Uri(AuthFeedUri), FeedUsername, FeedPassword, true, 1,
var pkg = downloader.DownloadPackage("mychart", new SemanticVersion("0.3.7"), "helm-feed", new Uri(authFeedUri), feedUsername, feedPassword, true, 1,
TimeSpan.FromSeconds(3));
pkg.PackageId.Should().Be("mychart");
pkg.Version.Should().Be(new SemanticVersion("0.3.7"));
}

[Test]
public void PackageWithInvalidUrl_Throws()
public async Task PackageWithInvalidUrl_Throws()
{
var badUrl = new Uri($"https://octopusdeploy.jfrog.io/gobbelygook/{Guid.NewGuid().ToString("N")}");
var baseUrl = await ExternalVariables.Get(ExternalVariable.ArtifactoryUrl, cancellationToken);
var badUrl = new Uri($"{baseUrl}/gobbelygook/{Guid.NewGuid().ToString("N")}");
var badEndpointDownloader = new HelmChartPackageDownloader(CalamariPhysicalFileSystem.GetPhysicalFileSystem(), new InMemoryLog());
Action action = () => badEndpointDownloader.DownloadPackage("something", new SemanticVersion("99.9.7"), "gobbely", new Uri(badUrl, "something.99.9.7"), FeedUsername, FeedPassword, true, 1, TimeSpan.FromSeconds(3));
Action action = () => badEndpointDownloader.DownloadPackage("something", new SemanticVersion("99.9.7"), "gobbely", new Uri(badUrl, "something.99.9.7"), feedUsername, feedPassword, true, 1, TimeSpan.FromSeconds(3));
action.Should().Throw<Exception>().And.Message.Should().Contain("Unable to read Helm index file").And.Contain("404");
}
}
}
}