Skip to content

Commit f189304

Browse files
authored
Merge pull request #221 from contentstack/release/snyk-test-fixes
DX | 02-11-2026 | Release
2 parents 0496621 + b1c457c commit f189304

25 files changed

Lines changed: 182 additions & 188 deletions
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Linq;
3+
using System.Security.Cryptography;
4+
5+
namespace Contentstack.Management.Core.Tests.Helpers
6+
{
7+
/// <summary>
8+
/// Per-run generated values for tests that need credential-shaped inputs but must not
9+
/// commit literal secrets. None of these are real credentials.
10+
/// </summary>
11+
internal static class TestSecrets
12+
{
13+
private const string Base32Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
14+
15+
public static string Password => Guid.NewGuid().ToString("N");
16+
17+
public static string Username => "user-" + Guid.NewGuid().ToString("N").Substring(0, 12) + "@example.com";
18+
19+
public static string Token() => Guid.NewGuid().ToString("N");
20+
21+
/// <summary>A stack API key-shaped value (blt + hex) that does not exist on any stack.</summary>
22+
public static string BltKey() => "blt" + Guid.NewGuid().ToString("N").Substring(0, 16);
23+
24+
/// <summary>A valid RFC 4648 base32 string, suitable as a TOTP secret.</summary>
25+
public static string Base32Secret()
26+
{
27+
var bytes = new byte[10];
28+
RandomNumberGenerator.Fill(bytes);
29+
return new string(bytes.Select(b => Base32Alphabet[b % 32]).ToArray());
30+
}
31+
32+
/// <summary>A string that is not valid base32 (contains characters outside the alphabet).</summary>
33+
public static string InvalidBase32Secret() => "!@#" + Guid.NewGuid().ToString("N");
34+
35+
/// <summary>Alternates upper/lower case; used to check case-insensitive secret handling.</summary>
36+
public static string MixedCase(string value) =>
37+
new string(value.Select((c, i) => i % 2 == 0 ? char.ToUpperInvariant(c) : char.ToLowerInvariant(c)).ToArray());
38+
}
39+
}

‎Contentstack.Management.Core.Tests/IntegrationTest/Contentstack001_LoginTest.cs‎

Lines changed: 50 additions & 100 deletions
Large diffs are not rendered by default.

‎Contentstack.Management.Core.Tests/IntegrationTest/Contentstack003_StackTest.cs‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,9 @@ public async System.Threading.Tasks.Task Test013_Stack_Settings_Async()
388388
#region Negative and error-handling tests (Test014+)
389389

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

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

399395
private static void AssertStackApiKeyOrInconclusive()
400396
{
@@ -1002,7 +998,6 @@ public void Test056_Should_Fail_UpdateUserRole_Invalid_User_Uid_API()
1002998
{
1003999
new UserInvitation
10041000
{
1005-
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
10061001
Uid = "blt_fake_user_uid_99999",
10071002
Roles = new List<string> { "blt_fake_role_uid_99999" }
10081003
}
@@ -1027,7 +1022,6 @@ public async Task Test057_Should_Fail_UpdateUserRoleAsync_Invalid_Role_Uid_API()
10271022
{
10281023
new UserInvitation
10291024
{
1030-
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
10311025
Uid = "blt_fake_user_uid_88888",
10321026
Roles = new List<string> { "blt_fake_role_uid_88888" }
10331027
}

‎Contentstack.Management.Core.Tests/IntegrationTest/Contentstack011_GlobalFieldTest.cs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ public async System.Threading.Tasks.Task Test009_Should_Delete_Async_Global_Fiel
204204

205205
#region Constants
206206
private const string InvalidGlobalFieldUid = "non_existent_global_field_uid_12345";
207-
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
208-
// deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret
209-
private const string InvalidApiKey = "bltInvalidApiKey12345";
207+
private static readonly string InvalidApiKey = TestSecrets.BltKey();
210208
private static readonly string VeryLongTitle = new string('a', 300); // 300 characters
211209
private const string SqlInjectionTitle = "'; DROP TABLE global_fields; --";
212210
private const string XssTitle = "<script>alert('xss')</script>";

‎Contentstack.Management.Core.Tests/IntegrationTest/Contentstack013_AssetTest.cs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,6 @@ public async Task Test060_Should_Fail_With_Expired_Auth_Token_For_Asset_Operatio
23582358
var expiredTokenClient = new ContentstackClient(new ContentstackClientOptions()
23592359
{
23602360
Host = _client.contentstackOptions.Host,
2361-
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
23622361
Authtoken = "blt_expired_token_simulation_12345"
23632362
});
23642363
var expiredStack = expiredTokenClient.Stack(_stack.APIKey);
@@ -2393,7 +2392,6 @@ public async Task Test061_Should_Fail_With_Insufficient_Asset_Permissions()
23932392
var limitedPermClient = new ContentstackClient(new ContentstackClientOptions()
23942393
{
23952394
Host = _client.contentstackOptions.Host,
2396-
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
23972395
Authtoken = "blt_limited_permissions_token_12345"
23982396
});
23992397
var limitedStack = limitedPermClient.Stack(_stack.APIKey);
@@ -2526,7 +2524,6 @@ public async Task Test065_Should_Block_Unauthorized_Asset_Deletion()
25262524
var readOnlyClient = new ContentstackClient(new ContentstackClientOptions()
25272525
{
25282526
Host = _client.contentstackOptions.Host,
2529-
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
25302527
Authtoken = "blt_readonly_token_12345"
25312528
});
25322529
var readOnlyStack = readOnlyClient.Stack(_stack.APIKey);
@@ -2561,7 +2558,6 @@ public async Task Test066_Should_Handle_Session_Timeout_During_Upload()
25612558
var shortLivedClient = new ContentstackClient(new ContentstackClientOptions()
25622559
{
25632560
Host = _client.contentstackOptions.Host,
2564-
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
25652561
Authtoken = "blt_short_lived_token_12345"
25662562
});
25672563
var shortLivedStack = shortLivedClient.Stack(_stack.APIKey);
@@ -2612,7 +2608,6 @@ public async Task Test067_Should_Validate_Asset_Access_Token_Scopes()
26122608
var limitedScopeClient = new ContentstackClient(new ContentstackClientOptions()
26132609
{
26142610
Host = _client.contentstackOptions.Host,
2615-
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
26162611
Authtoken = "blt_limited_scope_token_12345"
26172612
});
26182613
var limitedScopeStack = limitedScopeClient.Stack(_stack.APIKey);

‎Contentstack.Management.Core.Tests/IntegrationTest/Contentstack016_DeliveryTokenTest.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class Contentstack016_DeliveryTokenTest
2727
private DeliveryTokenModel _testTokenModel;
2828

2929
// Constants for error testing
30-
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
3130
private const string NonExistentTokenUid = "blt00000000000000000000";
3231
private const string InvalidTokenUid = "invalid-uid-format";
3332
private const string MalformedTokenUid = "!@#$%^&*()";

‎Contentstack.Management.Core.Tests/IntegrationTest/Contentstack019_RoleTest.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public class Contentstack019_RoleTest
1919
/// <summary>
2020
/// UID that should not exist on any stack (for negative-path tests).
2121
/// </summary>
22-
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
2322
private const string NonExistentRoleUid = "blt0000000000000000";
2423

2524
private static ContentstackClient _client;
@@ -1643,7 +1642,6 @@ public void Test041_Should_Handle_Fetch_With_Invalid_Credentials_Sync()
16431642
var invalidClient = new ContentstackClient(new ContentstackClientOptions()
16441643
{
16451644
Host = _client.contentstackOptions.Host,
1646-
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
16471645
Authtoken = "blt_invalid_token_format"
16481646
});
16491647

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

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

‎Contentstack.Management.Core.Tests/IntegrationTest/Contentstack021_EntryVariantTest.cs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,6 @@ public async System.Threading.Tasks.Task Test006_Should_Fail_To_Create_Variant_F
488488

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

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

@@ -1242,7 +1241,6 @@ public void Test031_Should_Validate_Variant_Stack_Isolation_Sync()
12421241
TestOutputLogger.LogContext("TestScenario", "Test031_Should_Validate_Variant_Stack_Isolation_Sync");
12431242

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

@@ -1487,7 +1485,6 @@ public async Task Test037_Should_Validate_Variant_Stack_Isolation_Async()
14871485

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

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

@@ -1862,7 +1859,6 @@ public void Test046_Should_Accept_Operations_With_Broken_Dependencies_Sync()
18621859
TestOutputLogger.LogContext("TestScenario", "Test046_Should_Accept_Operations_With_Broken_Dependencies_Sync");
18631860

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

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

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

22322227
var variantDataWithBrokenRefs = new

‎Contentstack.Management.Core.Tests/IntegrationTest/Contentstack022_VariantGroupTest.cs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,6 @@ public async Task Test403_Should_Fail_With_Expired_Auth_Token()
16601660
var expiredTokenClient = new ContentstackClient(new ContentstackClientOptions()
16611661
{
16621662
Host = _client.contentstackOptions.Host,
1663-
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
16641663
Authtoken = "blt_expired_token_simulation_12345"
16651664
});
16661665
var expiredStack = expiredTokenClient.Stack(_stack.APIKey);
@@ -1701,7 +1700,6 @@ public async Task Test404_Should_Fail_With_Insufficient_Permissions()
17011700
var limitedPermClient = new ContentstackClient(new ContentstackClientOptions()
17021701
{
17031702
Host = _client.contentstackOptions.Host,
1704-
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
17051703
Authtoken = "blt_limited_permissions_token_12345"
17061704
});
17071705
var limitedStack = limitedPermClient.Stack(_stack.APIKey);
@@ -1769,7 +1767,6 @@ public async Task Test406_Should_Handle_Token_Refresh_Scenarios()
17691767
var shortLivedClient = new ContentstackClient(new ContentstackClientOptions()
17701768
{
17711769
Host = _client.contentstackOptions.Host,
1772-
// deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
17731770
Authtoken = "blt_short_lived_token_12345"
17741771
});
17751772
var shortLivedStack = shortLivedClient.Stack(_stack.APIKey);

‎Contentstack.Management.Core.Tests/IntegrationTest/Contentstack023_PreviewTokenTest.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class Contentstack023_PreviewTokenTest
2727
private Stack _stack;
2828
private string _deliveryTokenUid;
2929

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

0 commit comments

Comments
 (0)