Skip to content
Open
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
39 changes: 39 additions & 0 deletions Contentstack.Management.Core.Tests/Helpers/TestSecrets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Linq;
using System.Security.Cryptography;

namespace Contentstack.Management.Core.Tests.Helpers
{
/// <summary>
/// Per-run generated values for tests that need credential-shaped inputs but must not
/// commit literal secrets. None of these are real credentials.
/// </summary>
internal static class TestSecrets
{
private const string Base32Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";

public static string Password => Guid.NewGuid().ToString("N");

public static string Username => "user-" + Guid.NewGuid().ToString("N").Substring(0, 12) + "@example.com";

public static string Token() => Guid.NewGuid().ToString("N");

/// <summary>A stack API key-shaped value (blt + hex) that does not exist on any stack.</summary>
public static string BltKey() => "blt" + Guid.NewGuid().ToString("N").Substring(0, 16);

/// <summary>A valid RFC 4648 base32 string, suitable as a TOTP secret.</summary>
public static string Base32Secret()
{
var bytes = new byte[10];
RandomNumberGenerator.Fill(bytes);
return new string(bytes.Select(b => Base32Alphabet[b % 32]).ToArray());
}

/// <summary>A string that is not valid base32 (contains characters outside the alphabet).</summary>
public static string InvalidBase32Secret() => "!@#" + Guid.NewGuid().ToString("N");

/// <summary>Alternates upper/lower case; used to check case-insensitive secret handling.</summary>
public static string MixedCase(string value) =>
new string(value.Select((c, i) => i % 2 == 0 ? char.ToUpperInvariant(c) : char.ToLowerInvariant(c)).ToArray());
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,9 @@ public async System.Threading.Tasks.Task Test013_Stack_Settings_Async()
#region Negative and error-handling tests (Test014+)

/// <summary>Non-empty API key used only to exercise SDK preconditions without requiring Test003 to succeed.</summary>
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
// deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret
private const string SdkNonEmptyApiKey = "bltSdkValidationNonEmptyApiKey00";
private static readonly string SdkNonEmptyApiKey = TestSecrets.BltKey();

// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
// deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret
private const string InvalidStackApiKey = "bltNonExistentStackKey12345";
private static readonly string InvalidStackApiKey = TestSecrets.BltKey();

private static void AssertStackApiKeyOrInconclusive()
{
Expand Down Expand Up @@ -1002,7 +998,6 @@ public void Test056_Should_Fail_UpdateUserRole_Invalid_User_Uid_API()
{
new UserInvitation
{
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
Uid = "blt_fake_user_uid_99999",
Roles = new List<string> { "blt_fake_role_uid_99999" }
}
Expand All @@ -1027,7 +1022,6 @@ public async Task Test057_Should_Fail_UpdateUserRoleAsync_Invalid_Role_Uid_API()
{
new UserInvitation
{
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
Uid = "blt_fake_user_uid_88888",
Roles = new List<string> { "blt_fake_role_uid_88888" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ public async System.Threading.Tasks.Task Test009_Should_Delete_Async_Global_Fiel

#region Constants
private const string InvalidGlobalFieldUid = "non_existent_global_field_uid_12345";
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
// deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret
private const string InvalidApiKey = "bltInvalidApiKey12345";
private static readonly string InvalidApiKey = TestSecrets.BltKey();
private static readonly string VeryLongTitle = new string('a', 300); // 300 characters
private const string SqlInjectionTitle = "'; DROP TABLE global_fields; --";
private const string XssTitle = "<script>alert('xss')</script>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2358,7 +2358,6 @@ public async Task Test060_Should_Fail_With_Expired_Auth_Token_For_Asset_Operatio
var expiredTokenClient = new ContentstackClient(new ContentstackClientOptions()
{
Host = _client.contentstackOptions.Host,
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
Authtoken = "blt_expired_token_simulation_12345"
});
var expiredStack = expiredTokenClient.Stack(_stack.APIKey);
Expand Down Expand Up @@ -2393,7 +2392,6 @@ public async Task Test061_Should_Fail_With_Insufficient_Asset_Permissions()
var limitedPermClient = new ContentstackClient(new ContentstackClientOptions()
{
Host = _client.contentstackOptions.Host,
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
Authtoken = "blt_limited_permissions_token_12345"
});
var limitedStack = limitedPermClient.Stack(_stack.APIKey);
Expand Down Expand Up @@ -2526,7 +2524,6 @@ public async Task Test065_Should_Block_Unauthorized_Asset_Deletion()
var readOnlyClient = new ContentstackClient(new ContentstackClientOptions()
{
Host = _client.contentstackOptions.Host,
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
Authtoken = "blt_readonly_token_12345"
});
var readOnlyStack = readOnlyClient.Stack(_stack.APIKey);
Expand Down Expand Up @@ -2561,7 +2558,6 @@ public async Task Test066_Should_Handle_Session_Timeout_During_Upload()
var shortLivedClient = new ContentstackClient(new ContentstackClientOptions()
{
Host = _client.contentstackOptions.Host,
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
Authtoken = "blt_short_lived_token_12345"
});
var shortLivedStack = shortLivedClient.Stack(_stack.APIKey);
Expand Down Expand Up @@ -2612,7 +2608,6 @@ public async Task Test067_Should_Validate_Asset_Access_Token_Scopes()
var limitedScopeClient = new ContentstackClient(new ContentstackClientOptions()
{
Host = _client.contentstackOptions.Host,
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
Authtoken = "blt_limited_scope_token_12345"
});
var limitedScopeStack = limitedScopeClient.Stack(_stack.APIKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class Contentstack016_DeliveryTokenTest
private DeliveryTokenModel _testTokenModel;

// Constants for error testing
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
private const string NonExistentTokenUid = "blt00000000000000000000";
private const string InvalidTokenUid = "invalid-uid-format";
private const string MalformedTokenUid = "!@#$%^&*()";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class Contentstack019_RoleTest
/// <summary>
/// UID that should not exist on any stack (for negative-path tests).
/// </summary>
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
private const string NonExistentRoleUid = "blt0000000000000000";

private static ContentstackClient _client;
Expand Down Expand Up @@ -1643,7 +1642,6 @@ public void Test041_Should_Handle_Fetch_With_Invalid_Credentials_Sync()
var invalidClient = new ContentstackClient(new ContentstackClientOptions()
{
Host = _client.contentstackOptions.Host,
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
Authtoken = "blt_invalid_token_format"
});

Expand Down Expand Up @@ -2002,7 +2000,6 @@ public void Test049_Should_Validate_Role_Stack_Isolation_Sync()
try
{
// Attempt to access role using different stack context
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
var differentStackKey = "blt_fake_stack_key_12345";
var differentStack = _client.Stack(differentStackKey);

Expand Down Expand Up @@ -2138,7 +2135,6 @@ public async Task Test052_Should_Validate_Role_Stack_Isolation_Async()
try
{
// Attempt to access role using different stack context
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
var differentStackKey = "blt_fake_stack_key_async_12345";
var differentStack = _client.Stack(differentStackKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ public async System.Threading.Tasks.Task Test006_Should_Fail_To_Create_Variant_F

TestOutputLogger.LogContext("TestScenario", "ProductBannerVariantLifecycle_Create_Negative");

// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
var invalidEntryUid = "blt_invalid_entry_uid";
var variantData = new { banner_color = "Navy Blue", _variant = new { _change_set = new[] { "banner_color" } } };

Expand Down Expand Up @@ -1242,7 +1241,6 @@ public void Test031_Should_Validate_Variant_Stack_Isolation_Sync()
TestOutputLogger.LogContext("TestScenario", "Test031_Should_Validate_Variant_Stack_Isolation_Sync");

// Attempt to access variant using different stack context
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
var differentStackKey = "blt_fake_stack_key_12345";
var differentStack = _client.Stack(differentStackKey);

Expand Down Expand Up @@ -1487,7 +1485,6 @@ public async Task Test037_Should_Validate_Variant_Stack_Isolation_Async()

TestOutputLogger.LogContext("TestScenario", "Test037_Should_Validate_Variant_Stack_Isolation_Async");

// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
var differentStackKey = "blt_fake_stack_key_async_12345";
var differentStack = _client.Stack(differentStackKey);

Expand Down Expand Up @@ -1862,7 +1859,6 @@ public void Test046_Should_Accept_Operations_With_Broken_Dependencies_Sync()
TestOutputLogger.LogContext("TestScenario", "Test046_Should_Accept_Operations_With_Broken_Dependencies_Sync");

// API is permissive with broken references - ignores invalid reference fields
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
var deletedEntryUid = "blt_deleted_entry_12345";

var variantDataWithBrokenRefs = new
Expand Down Expand Up @@ -2226,7 +2222,6 @@ public async Task Test054_Should_Accept_Operations_With_Broken_Dependencies_Asyn
TestOutputLogger.LogContext("TestScenario", "Test054_Should_Accept_Operations_With_Broken_Dependencies_Async");

// API is permissive with broken references - ignores invalid reference fields
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
var deletedEntryUid = "blt_deleted_entry_async_12345";

var variantDataWithBrokenRefs = new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,6 @@ public async Task Test403_Should_Fail_With_Expired_Auth_Token()
var expiredTokenClient = new ContentstackClient(new ContentstackClientOptions()
{
Host = _client.contentstackOptions.Host,
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
Authtoken = "blt_expired_token_simulation_12345"
});
var expiredStack = expiredTokenClient.Stack(_stack.APIKey);
Expand Down Expand Up @@ -1701,7 +1700,6 @@ public async Task Test404_Should_Fail_With_Insufficient_Permissions()
var limitedPermClient = new ContentstackClient(new ContentstackClientOptions()
{
Host = _client.contentstackOptions.Host,
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
Authtoken = "blt_limited_permissions_token_12345"
});
var limitedStack = limitedPermClient.Stack(_stack.APIKey);
Expand Down Expand Up @@ -1769,7 +1767,6 @@ public async Task Test406_Should_Handle_Token_Refresh_Scenarios()
var shortLivedClient = new ContentstackClient(new ContentstackClientOptions()
{
Host = _client.contentstackOptions.Host,
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
Authtoken = "blt_short_lived_token_12345"
});
var shortLivedStack = shortLivedClient.Stack(_stack.APIKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class Contentstack023_PreviewTokenTest
private Stack _stack;
private string _deliveryTokenUid;

// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
private const string NonExistentTokenUid = "blt00000000000000000000";
private const string InvalidTokenUid = "invalid-uid-format";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Contentstack.Management.Core.Unit.Tests.Helpers;
using System;
using System.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand All @@ -9,9 +10,7 @@ public class ContentstackConfigTest
{
readonly string Host = "10.0.0.1";
readonly int Port = 20;
// deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret
readonly string UserName= "test_user_name";
// deepcode ignore NoHardcodedPasswords: test fixture value, not a real secret
readonly string UserName= TestSecrets.Token();
readonly string Password = "password";
readonly string Authtoken = "Authtoken";
readonly long MaxContentSize = 8589934592;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Contentstack.Management.Core.Unit.Tests.Helpers;
using System;
using System.Text;
using AutoFixture;
Expand Down Expand Up @@ -109,8 +110,7 @@ public void Should_Create_Content_Body_From_Data()
public void Should_Create_Service_With_Stack_Having_API_Key()
{
var data = new BulkAddItemsData();
// deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret
var apiKey = "test-api-key";
var apiKey = TestSecrets.Token();
var stack = new Management.Core.Models.Stack(null, apiKey);
var service = new BulkAddItemsService(serializer, stack, data);

Expand Down Expand Up @@ -149,8 +149,7 @@ public void Should_Create_Service_With_Stack_Having_Branch_Uid()
public void Should_Create_Service_With_All_Stack_Parameters()
{
var data = new BulkAddItemsData();
// deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret
var apiKey = "test-api-key";
var apiKey = TestSecrets.Token();
var managementToken = "test-management-token";
var branchUid = "test-branch-uid";
var stack = new Management.Core.Models.Stack(null, apiKey, managementToken, branchUid);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Contentstack.Management.Core.Unit.Tests.Helpers;
using System;
using System.Text;
using AutoFixture;
Expand Down Expand Up @@ -64,8 +65,7 @@ public void Should_Create_Content_Body_From_Details()
public void Should_Create_Service_With_Stack_Having_API_Key()
{
var details = new BulkDeleteDetails();
// deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret
var apiKey = "test-api-key";
var apiKey = TestSecrets.Token();
var stack = new Management.Core.Models.Stack(null, apiKey);
var service = new BulkDeleteService(serializer, stack, details);

Expand Down Expand Up @@ -104,8 +104,7 @@ public void Should_Create_Service_With_Stack_Having_Branch_Uid()
public void Should_Create_Service_With_All_Stack_Parameters()
{
var details = new BulkDeleteDetails();
// deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret
var apiKey = "test-api-key";
var apiKey = TestSecrets.Token();
var managementToken = "test-management-token";
var branchUid = "test-branch-uid";
var stack = new Management.Core.Models.Stack(null, apiKey, managementToken, branchUid);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Contentstack.Management.Core.Unit.Tests.Helpers;
using System;
using AutoFixture;
using AutoFixture.AutoMoq;
Expand Down Expand Up @@ -99,8 +100,7 @@ public void Should_Set_Bulk_Version_Header_With_Complex_Version()
public void Should_Create_Service_With_Stack_Having_API_Key()
{
var jobId = "test-job-id";
// deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret
var apiKey = "test-api-key";
var apiKey = TestSecrets.Token();
var stack = new Management.Core.Models.Stack(null, apiKey);
var service = new BulkJobStatusService(serializer, stack, jobId);

Expand Down Expand Up @@ -139,8 +139,7 @@ public void Should_Create_Service_With_Stack_Having_Branch_Uid()
public void Should_Create_Service_With_All_Stack_Parameters()
{
var jobId = "test-job-id";
// deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret
var apiKey = "test-api-key";
var apiKey = TestSecrets.Token();
var managementToken = "test-management-token";
var branchUid = "test-branch-uid";
var stack = new Management.Core.Models.Stack(null, apiKey, managementToken, branchUid);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Contentstack.Management.Core.Unit.Tests.Helpers;
using System;
using System.Text;
using AutoFixture;
Expand Down Expand Up @@ -88,8 +89,7 @@ public void Should_Set_Nested_Query_Parameters_When_True()
public void Should_Create_Service_With_Stack_Having_API_Key()
{
var details = new BulkPublishDetails();
// deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret
var apiKey = "test-api-key";
var apiKey = TestSecrets.Token();
var stack = new Management.Core.Models.Stack(null, apiKey);
var service = new BulkPublishService(serializer, stack, details);

Expand Down Expand Up @@ -128,8 +128,7 @@ public void Should_Create_Service_With_Stack_Having_Branch_Uid()
public void Should_Create_Service_With_All_Stack_Parameters()
{
var details = new BulkPublishDetails();
// deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret
var apiKey = "test-api-key";
var apiKey = TestSecrets.Token();
var managementToken = "test-management-token";
var branchUid = "test-branch-uid";
var stack = new Management.Core.Models.Stack(null, apiKey, managementToken, branchUid);
Expand Down
Loading
Loading