Skip to content

Commit

Permalink
Fix cred scan (Azure-App-Service#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazhzeng authored Jan 14, 2021
1 parent e7cd73a commit 11f5623
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Kudu.Tests/Services/Models/EncryptedHostAssignmentContextTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Buffers.Text;
using System.Collections.Generic;
using System.Text;
using Kudu.Services.Models;
using Xunit;

namespace Kudu.Tests.Services.Models
{
public class EncryptedHostAssignmentContextTests
{
private const string _lastModifiedTime = "2019-01-15T15:53:00";
private HostAssignmentContext _context = new HostAssignmentContext() {
SiteId = 10,
SiteName = "sitename",
LastModifiedTime = DateTime.Parse(_lastModifiedTime),
Environment = new Dictionary<string, string>()
{
{"APPSETTING_AzureWebJobsStorage", "<StorageString>"},
{"APPSETTING_SCM_RUN_FROM_PACKAGE", "1"},
{"APPSETTING_SCM_DO_BUILD_DURING_DEPLOYMENT", "true"},
{"APPSETTING_SCM_NO_REPOSITORY", "1"},
{"ENABLE_ORYX_BUILD", "true"},
{"FRAMEWORK", "PYTHON"},
{"FRAMEWORK_VERSION", "3.6"}
}
};

[Fact]
public void EncryptedContextShouldExistAfterCreate()
{
var result = EncryptedHostAssignmentContext.Create(_context, GetMockedEncryptionKey());
Assert.NotEmpty(result.EncryptedContext);
}

[Fact]
public void DecryptedContextShouldMatchByEqual()
{
var encrypted = EncryptedHostAssignmentContext.Create(_context, GetMockedEncryptionKey());
var decrypted = encrypted.Decrypt(GetMockedEncryptionKey());
Assert.True(_context.Equals(decrypted));
}

[Fact]
public void DecryptedContextShouldMatchEnvironments()
{
var encrypted = EncryptedHostAssignmentContext.Create(_context, GetMockedEncryptionKey());
var decrypted = encrypted.Decrypt(GetMockedEncryptionKey());
Assert.Equal(_context.Environment, decrypted.Environment);
}

private string GetMockedEncryptionKey()
{
var bytes = Encoding.ASCII.GetBytes("0123456789ABCDEF0123456789ABCDEF");
return Convert.ToBase64String(bytes);
}
}
}

0 comments on commit 11f5623

Please sign in to comment.