diff --git a/Contentstack.Management.Core.Tests/Helpers/TestSecrets.cs b/Contentstack.Management.Core.Tests/Helpers/TestSecrets.cs new file mode 100644 index 0000000..291f8f0 --- /dev/null +++ b/Contentstack.Management.Core.Tests/Helpers/TestSecrets.cs @@ -0,0 +1,39 @@ +using System; +using System.Linq; +using System.Security.Cryptography; + +namespace Contentstack.Management.Core.Tests.Helpers +{ + /// + /// Per-run generated values for tests that need credential-shaped inputs but must not + /// commit literal secrets. None of these are real credentials. + /// + 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"); + + /// A stack API key-shaped value (blt + hex) that does not exist on any stack. + public static string BltKey() => "blt" + Guid.NewGuid().ToString("N").Substring(0, 16); + + /// A valid RFC 4648 base32 string, suitable as a TOTP secret. + public static string Base32Secret() + { + var bytes = new byte[10]; + RandomNumberGenerator.Fill(bytes); + return new string(bytes.Select(b => Base32Alphabet[b % 32]).ToArray()); + } + + /// A string that is not valid base32 (contains characters outside the alphabet). + public static string InvalidBase32Secret() => "!@#" + Guid.NewGuid().ToString("N"); + + /// Alternates upper/lower case; used to check case-insensitive secret handling. + public static string MixedCase(string value) => + new string(value.Select((c, i) => i % 2 == 0 ? char.ToUpperInvariant(c) : char.ToLowerInvariant(c)).ToArray()); + } +} diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack001_LoginTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack001_LoginTest.cs index 572f166..95a2d5a 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack001_LoginTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack001_LoginTest.cs @@ -29,8 +29,7 @@ public void Test001_Should_Return_Failuer_On_Wrong_Login_Credentials() { TestOutputLogger.LogContext("TestScenario", "WrongCredentials"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("mock_user", "mock_pasword"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); try { @@ -51,8 +50,7 @@ public async System.Threading.Tasks.Task Test002_Should_Return_Failuer_On_Wrong_ { TestOutputLogger.LogContext("TestScenario", "WrongCredentialsAsync"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("mock_user", "mock_pasword"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); try { @@ -220,10 +218,8 @@ public void Test008_Should_Fail_Login_With_Invalid_MfaSecret() { TestOutputLogger.LogContext("TestScenario", "InvalidMfaSecret"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test_user", "test_password"); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - string invalidMfaSecret = "INVALID_BASE32_SECRET!@#"; + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); + string invalidMfaSecret = TestSecrets.InvalidBase32Secret(); try { @@ -246,10 +242,8 @@ public void Test009_Should_Generate_TOTP_Token_With_Valid_MfaSecret() { TestOutputLogger.LogContext("TestScenario", "ValidMfaSecret"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test_user", "test_password"); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - string validMfaSecret = "JBSWY3DPEHPK3PXP"; + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); + string validMfaSecret = TestSecrets.Base32Secret(); try { @@ -278,10 +272,8 @@ public async System.Threading.Tasks.Task Test010_Should_Generate_TOTP_Token_With { TestOutputLogger.LogContext("TestScenario", "ValidMfaSecretAsync"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test_user", "test_password"); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - string validMfaSecret = "JBSWY3DPEHPK3PXP"; + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); + string validMfaSecret = TestSecrets.Base32Secret(); try { @@ -310,10 +302,8 @@ public void Test011_Should_Prefer_Explicit_Token_Over_MfaSecret() { TestOutputLogger.LogContext("TestScenario", "ExplicitTokenOverMfa"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test_user", "test_password"); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - string validMfaSecret = "JBSWY3DPEHPK3PXP"; + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); + string validMfaSecret = TestSecrets.Base32Secret(); string explicitToken = "123456"; try @@ -431,10 +421,8 @@ public async System.Threading.Tasks.Task Test016_Should_Throw_ArgumentException_ { TestOutputLogger.LogContext("TestScenario", "InvalidMfaSecretAsync"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test_user", "test_password"); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - string invalidMfaSecret = "INVALID_BASE32_SECRET!@#"; + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); + string invalidMfaSecret = TestSecrets.InvalidBase32Secret(); try { @@ -537,8 +525,7 @@ public void Test019_Should_Not_Include_TfaToken_When_MfaSecret_Is_Empty_Sync() { TestOutputLogger.LogContext("TestScenario", "EmptyMfaSecretSync"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("mock_user", "mock_password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); try { @@ -561,8 +548,7 @@ public async System.Threading.Tasks.Task Test020_Should_Not_Include_TfaToken_Whe { TestOutputLogger.LogContext("TestScenario", "NullMfaSecretAsync"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("mock_user", "mock_password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); try { @@ -602,8 +588,7 @@ public void Test022_Should_Handle_Empty_Password_Sync() { TestOutputLogger.LogContext("TestScenario", "EmptyPasswordSync"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("user@example.com", ""); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); var ex = AssertLogger.ThrowsContentstackError(() => client.Login(credentials), "EmptyPassword", HttpStatusCode.UnprocessableEntity); @@ -633,8 +618,7 @@ public async System.Threading.Tasks.Task Test024_Should_Handle_Empty_Password_As { TestOutputLogger.LogContext("TestScenario", "EmptyPasswordAsync"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("user@example.com", ""); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); var ex = await AssertLogger.ThrowsContentstackErrorAsync(() => client.LoginAsync(credentials), "EmptyPasswordAsync", HttpStatusCode.UnprocessableEntity); @@ -700,8 +684,7 @@ public void Test026_Should_Handle_Network_Timeout_Sync() { TestOutputLogger.LogContext("TestScenario", "NetworkTimeoutSync"); ContentstackClient client = CreateClientWithMockError(NetworkErrorType.Timeout); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); try { @@ -728,8 +711,7 @@ public async System.Threading.Tasks.Task Test027_Should_Handle_Network_Timeout_A { TestOutputLogger.LogContext("TestScenario", "NetworkTimeoutAsync"); ContentstackClient client = CreateClientWithMockError(NetworkErrorType.Timeout); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); try { @@ -756,8 +738,7 @@ public void Test028_Should_Handle_Connection_Refused_Sync() { TestOutputLogger.LogContext("TestScenario", "ConnectionRefusedSync"); ContentstackClient client = CreateClientWithMockError(NetworkErrorType.ConnectionRefused); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); AssertLogger.ThrowsException(() => client.Login(credentials), "ConnectionRefused"); @@ -769,8 +750,7 @@ public async System.Threading.Tasks.Task Test029_Should_Handle_Connection_Refuse { TestOutputLogger.LogContext("TestScenario", "ConnectionRefusedAsync"); ContentstackClient client = CreateClientWithMockError(NetworkErrorType.ConnectionRefused); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); await AssertLogger.ThrowsExceptionAsync(() => client.LoginAsync(credentials), "ConnectionRefusedAsync"); @@ -782,8 +762,7 @@ public void Test030_Should_Handle_DNS_Resolution_Failure_Sync() { TestOutputLogger.LogContext("TestScenario", "DnsFailureSync"); ContentstackClient client = CreateClientWithMockError(NetworkErrorType.DnsFailure); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); AssertLogger.ThrowsException(() => client.Login(credentials), "DnsFailure"); @@ -795,8 +774,7 @@ public async System.Threading.Tasks.Task Test031_Should_Handle_DNS_Resolution_Fa { TestOutputLogger.LogContext("TestScenario", "DnsFailureAsync"); ContentstackClient client = CreateClientWithMockError(NetworkErrorType.DnsFailure); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); await AssertLogger.ThrowsExceptionAsync(() => client.LoginAsync(credentials), "DnsFailureAsync"); @@ -816,8 +794,7 @@ public void Test032_Should_Handle_Request_Cancellation_Sync() { TestOutputLogger.LogContext("TestScenario", "RequestCancellationSync"); ContentstackClient client = CreateClientWithTimeout(100); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); try { @@ -871,8 +848,7 @@ public void Test033_Should_Handle_401_Unauthorized_Sync() TestOutputLogger.LogContext("TestScenario", "Http401UnauthorizedSync"); ContentstackClient client = CreateClientWithHttpStatus(HttpStatusCode.Unauthorized, "Authentication failed. Please check your credentials.", 401); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); var ex = AssertLogger.ThrowsContentstackError(() => client.Login(credentials), "Unauthorized", HttpStatusCode.Unauthorized); @@ -888,8 +864,7 @@ public async System.Threading.Tasks.Task Test034_Should_Handle_401_Unauthorized_ TestOutputLogger.LogContext("TestScenario", "Http401UnauthorizedAsync"); ContentstackClient client = CreateClientWithHttpStatus(HttpStatusCode.Unauthorized, "Authentication failed. Please check your credentials.", 401); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); var ex = await AssertLogger.ThrowsContentstackErrorAsync(() => client.LoginAsync(credentials), "UnauthorizedAsync", HttpStatusCode.Unauthorized); @@ -905,8 +880,7 @@ public void Test035_Should_Handle_403_Forbidden_Sync() TestOutputLogger.LogContext("TestScenario", "Http403ForbiddenSync"); ContentstackClient client = CreateClientWithHttpStatus(HttpStatusCode.Forbidden, "Access denied. Insufficient permissions.", 403); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); var ex = AssertLogger.ThrowsContentstackError(() => client.Login(credentials), "Forbidden", HttpStatusCode.Forbidden); @@ -922,8 +896,7 @@ public async System.Threading.Tasks.Task Test036_Should_Handle_403_Forbidden_Asy TestOutputLogger.LogContext("TestScenario", "Http403ForbiddenAsync"); ContentstackClient client = CreateClientWithHttpStatus(HttpStatusCode.Forbidden, "Access denied. Insufficient permissions.", 403); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); var ex = await AssertLogger.ThrowsContentstackErrorAsync(() => client.LoginAsync(credentials), "ForbiddenAsync", HttpStatusCode.Forbidden); @@ -939,8 +912,7 @@ public void Test050_Should_Handle_429_TooManyRequests_Sync() TestOutputLogger.LogContext("TestScenario", "Http429TooManyRequestsSync"); ContentstackClient client = CreateClientWithHttpStatus(HttpStatusCode.TooManyRequests, "Rate limit exceeded. Please try again later.", 429); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); var ex = AssertLogger.ThrowsContentstackError(() => client.Login(credentials), "TooManyRequests", HttpStatusCode.TooManyRequests); @@ -956,8 +928,7 @@ public async System.Threading.Tasks.Task Test051_Should_Handle_429_TooManyReques TestOutputLogger.LogContext("TestScenario", "Http429TooManyRequestsAsync"); ContentstackClient client = CreateClientWithHttpStatus(HttpStatusCode.TooManyRequests, "Rate limit exceeded. Please try again later.", 429); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); var ex = await AssertLogger.ThrowsContentstackErrorAsync(() => client.LoginAsync(credentials), "TooManyRequestsAsync", HttpStatusCode.TooManyRequests); @@ -973,8 +944,7 @@ public void Test052_Should_Handle_500_InternalServerError_Sync() TestOutputLogger.LogContext("TestScenario", "Http500InternalServerErrorSync"); ContentstackClient client = CreateClientWithHttpStatusNoRetry(HttpStatusCode.InternalServerError, "Internal server error occurred.", 500); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); var ex = AssertLogger.ThrowsContentstackError(() => client.Login(credentials), "InternalServerError", HttpStatusCode.InternalServerError); @@ -990,8 +960,7 @@ public async System.Threading.Tasks.Task Test053_Should_Handle_500_InternalServe TestOutputLogger.LogContext("TestScenario", "Http500InternalServerErrorAsync"); ContentstackClient client = CreateClientWithHttpStatusNoRetry(HttpStatusCode.InternalServerError, "Internal server error occurred.", 500); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); var ex = await AssertLogger.ThrowsContentstackErrorAsync(() => client.LoginAsync(credentials), "InternalServerErrorAsync", HttpStatusCode.InternalServerError); @@ -1020,8 +989,7 @@ public void Test056_Should_Handle_Malformed_JSON_Response_Sync() { TestOutputLogger.LogContext("TestScenario", "MalformedJsonSync"); ContentstackClient client = CreateClientWithMalformedResponse("{ invalid json }"); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); try { @@ -1048,8 +1016,7 @@ public async System.Threading.Tasks.Task Test057_Should_Handle_Malformed_JSON_Re { TestOutputLogger.LogContext("TestScenario", "MalformedJsonAsync"); ContentstackClient client = CreateClientWithMalformedResponse("{ invalid json }"); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); try { @@ -1076,8 +1043,7 @@ public void Test058_Should_Handle_Empty_Response_Body_Sync() { TestOutputLogger.LogContext("TestScenario", "EmptyResponseSync"); ContentstackClient client = CreateClientWithMalformedResponse("", HttpStatusCode.OK); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); try { @@ -1108,8 +1074,7 @@ public async System.Threading.Tasks.Task Test059_Should_Handle_Empty_Response_Bo { TestOutputLogger.LogContext("TestScenario", "EmptyResponseAsync"); ContentstackClient client = CreateClientWithMalformedResponse("", HttpStatusCode.OK); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); try { @@ -1148,8 +1113,7 @@ public void Test060_Should_Handle_Unexpected_Response_Structure_Sync() ""status"": ""success"" }"; ContentstackClient client = CreateClientWithMalformedResponse(unexpectedResponse, HttpStatusCode.OK); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); try { @@ -1201,8 +1165,7 @@ public void Test061_Should_Handle_Large_Response_Payload_Sync() ""large_data"": ""{largeData}"" }}"; ContentstackClient client = CreateClientWithMalformedResponse(largeResponse, HttpStatusCode.BadRequest); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); var ex = AssertLogger.ThrowsContentstackError(() => client.Login(credentials), "LargeResponse", HttpStatusCode.BadRequest); @@ -1528,8 +1491,7 @@ public void Test088_Should_Handle_TOTP_Token_Format_Variations_Sync() { TestOutputLogger.LogContext("TestScenario", "TotpTokenFormatSync"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); // Test various TOTP token formats string[] tokenFormats = { @@ -1574,8 +1536,7 @@ public async System.Threading.Tasks.Task Test089_Should_Handle_TOTP_Token_Format { TestOutputLogger.LogContext("TestScenario", "TotpTokenFormatAsync"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); // Test numeric edge cases string[] numericTokens = { @@ -1609,8 +1570,7 @@ public void Test090_Should_Handle_MFA_Secret_Edge_Cases_Sync() { TestOutputLogger.LogContext("TestScenario", "MfaSecretEdgeCasesSync"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); // Test MFA secret edge cases string[] edgeCaseSecrets = { @@ -1653,13 +1613,11 @@ public void Test091_Should_Handle_Both_Token_And_MFA_Secret_Provided_Sync() { TestOutputLogger.LogContext("TestScenario", "BothTokenAndMfaSync"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); // Test providing both explicit token and MFA secret string explicitToken = "123456"; - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - string mfaSecret = "JBSWY3DPEHPK3PXP"; + string mfaSecret = TestSecrets.Base32Secret(); try { @@ -1683,8 +1641,7 @@ public async System.Threading.Tasks.Task Test092_Should_Handle_Both_Token_And_MF { TestOutputLogger.LogContext("TestScenario", "BothTokenAndMfaAsync"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); // Test providing both with different combinations var testCases = new[] @@ -1718,16 +1675,12 @@ public void Test093_Should_Handle_MFA_Secret_Case_Sensitivity_Sync() { TestOutputLogger.LogContext("TestScenario", "MfaSecretCaseSync"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); // Test case sensitivity in MFA secrets - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - string upperSecret = "JBSWY3DPEHPK3PXP"; - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - string lowerSecret = "jbswy3dpehpk3pxp"; - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - string mixedSecret = "JbSwY3dPeHpK3pXp"; + string upperSecret = TestSecrets.Base32Secret(); + string lowerSecret = upperSecret.ToLowerInvariant(); + string mixedSecret = TestSecrets.MixedCase(upperSecret); string[] secrets = { upperSecret, lowerSecret, mixedSecret }; @@ -1761,8 +1714,7 @@ public void Test095_Should_Handle_MFA_Parameter_Boundary_Conditions_Sync() { TestOutputLogger.LogContext("TestScenario", "MfaBoundaryConditionsSync"); ContentstackClient client = CreateClientWithLogging(); - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - NetworkCredential credentials = new NetworkCredential("test@example.com", "password"); + NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); // Test boundary conditions for MFA parameters var boundaryTests = new[] @@ -1814,8 +1766,7 @@ public async System.Threading.Tasks.Task Test096_Should_Handle_Concurrent_Login_ } // Use invalid credentials to test concurrent error handling - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - var credentials = new NetworkCredential("concurrent_test", "invalid_password"); + var credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); try { @@ -1874,8 +1825,7 @@ public async System.Threading.Tasks.Task Test100_Should_Validate_Complete_Error_ { ("NullCredentials", () => CreateClientWithLogging().LoginAsync(null)), ("EmptyCredentials", () => CreateClientWithLogging().LoginAsync(new NetworkCredential("", ""))), - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - ("InvalidCredentials", () => CreateClientWithLogging().LoginAsync(new NetworkCredential("invalid", "invalid"))), + ("InvalidCredentials", () => CreateClientWithLogging().LoginAsync(new NetworkCredential(TestSecrets.Username, TestSecrets.Password))), ("NetworkError", () => CreateClientWithMockError(NetworkErrorType.Timeout, 100).LoginAsync(new NetworkCredential("test", "test"))), ("HttpError", () => CreateClientWithHttpStatusNoRetry(HttpStatusCode.InternalServerError).LoginAsync(new NetworkCredential("test", "test"))), ("MalformedResponse", () => CreateClientWithMalformedResponse("invalid json").LoginAsync(new NetworkCredential("test", "test"))) diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack003_StackTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack003_StackTest.cs index 0d8d602..d4965e8 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack003_StackTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack003_StackTest.cs @@ -388,13 +388,9 @@ public async System.Threading.Tasks.Task Test013_Stack_Settings_Async() #region Negative and error-handling tests (Test014+) /// Non-empty API key used only to exercise SDK preconditions without requiring Test003 to succeed. - // 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() { @@ -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 { "blt_fake_role_uid_99999" } } @@ -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 { "blt_fake_role_uid_88888" } } diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack011_GlobalFieldTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack011_GlobalFieldTest.cs index f08fa83..593ead0 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack011_GlobalFieldTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack011_GlobalFieldTest.cs @@ -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 = ""; diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack013_AssetTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack013_AssetTest.cs index 91ad668..7e25ed7 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack013_AssetTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack013_AssetTest.cs @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack016_DeliveryTokenTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack016_DeliveryTokenTest.cs index 00412dc..99aa20d 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack016_DeliveryTokenTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack016_DeliveryTokenTest.cs @@ -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 = "!@#$%^&*()"; diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack019_RoleTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack019_RoleTest.cs index 7840573..19be766 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack019_RoleTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack019_RoleTest.cs @@ -19,7 +19,6 @@ public class Contentstack019_RoleTest /// /// UID that should not exist on any stack (for negative-path tests). /// - // deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret private const string NonExistentRoleUid = "blt0000000000000000"; private static ContentstackClient _client; @@ -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" }); @@ -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); @@ -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); diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack021_EntryVariantTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack021_EntryVariantTest.cs index aca7abe..ea753d7 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack021_EntryVariantTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack021_EntryVariantTest.cs @@ -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" } } }; @@ -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); @@ -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); @@ -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 @@ -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 diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack022_VariantGroupTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack022_VariantGroupTest.cs index 183eebd..c17aabf 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack022_VariantGroupTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack022_VariantGroupTest.cs @@ -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); @@ -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); @@ -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); diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack023_PreviewTokenTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack023_PreviewTokenTest.cs index 5defec5..dd57d32 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack023_PreviewTokenTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack023_PreviewTokenTest.cs @@ -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"; diff --git a/Contentstack.Management.Core.Unit.Tests/Configuration/ContentstackConfigTest.cs b/Contentstack.Management.Core.Unit.Tests/Configuration/ContentstackConfigTest.cs index c478424..544cdca 100644 --- a/Contentstack.Management.Core.Unit.Tests/Configuration/ContentstackConfigTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Configuration/ContentstackConfigTest.cs @@ -1,4 +1,5 @@ -using System; +using Contentstack.Management.Core.Unit.Tests.Helpers; +using System; using System.Net; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -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; diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkAddItemsServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkAddItemsServiceTest.cs index 044f27b..315f78c 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkAddItemsServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkAddItemsServiceTest.cs @@ -1,3 +1,4 @@ +using Contentstack.Management.Core.Unit.Tests.Helpers; using System; using System.Text; using AutoFixture; @@ -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); @@ -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); diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkDeleteServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkDeleteServiceTest.cs index dc5db01..097ff2b 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkDeleteServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkDeleteServiceTest.cs @@ -1,3 +1,4 @@ +using Contentstack.Management.Core.Unit.Tests.Helpers; using System; using System.Text; using AutoFixture; @@ -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); @@ -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); diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkJobStatusServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkJobStatusServiceTest.cs index fb0b9a8..9e25121 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkJobStatusServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkJobStatusServiceTest.cs @@ -1,3 +1,4 @@ +using Contentstack.Management.Core.Unit.Tests.Helpers; using System; using AutoFixture; using AutoFixture.AutoMoq; @@ -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); @@ -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); diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkPublishServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkPublishServiceTest.cs index b1f8873..8e6126f 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkPublishServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkPublishServiceTest.cs @@ -1,3 +1,4 @@ +using Contentstack.Management.Core.Unit.Tests.Helpers; using System; using System.Text; using AutoFixture; @@ -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); @@ -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); diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkReleaseItemsServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkReleaseItemsServiceTest.cs index 211b05f..c0e4a0d 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkReleaseItemsServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkReleaseItemsServiceTest.cs @@ -1,3 +1,4 @@ +using Contentstack.Management.Core.Unit.Tests.Helpers; using System; using System.Text; using AutoFixture; @@ -100,8 +101,7 @@ public void Should_Set_Bulk_Version_Header_With_Complex_Version() public void Should_Create_Service_With_Stack_Having_API_Key() { var data = new BulkReleaseItemsData(); - // 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 BulkReleaseItemsService(serializer, stack, data); @@ -140,8 +140,7 @@ public void Should_Create_Service_With_Stack_Having_Branch_Uid() public void Should_Create_Service_With_All_Stack_Parameters() { var data = new BulkReleaseItemsData(); - // 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); diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUnpublishServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUnpublishServiceTest.cs index 1c9ff41..3498941 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUnpublishServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUnpublishServiceTest.cs @@ -1,3 +1,4 @@ +using Contentstack.Management.Core.Unit.Tests.Helpers; using System; using System.Text; using AutoFixture; @@ -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 BulkUnpublishService(serializer, stack, details); @@ -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); diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUpdateItemsServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUpdateItemsServiceTest.cs index 1e43ef9..fe5a25f 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUpdateItemsServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUpdateItemsServiceTest.cs @@ -1,3 +1,4 @@ +using Contentstack.Management.Core.Unit.Tests.Helpers; using System; using System.Text; using AutoFixture; @@ -110,8 +111,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 BulkUpdateItemsService(serializer, stack, data); @@ -150,8 +150,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); diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkWorkflowUpdateServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkWorkflowUpdateServiceTest.cs index 9720262..4c8e69e 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkWorkflowUpdateServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkWorkflowUpdateServiceTest.cs @@ -1,3 +1,4 @@ +using Contentstack.Management.Core.Unit.Tests.Helpers; using System; using System.Text; using AutoFixture; @@ -54,8 +55,7 @@ public void Should_Create_Service_With_Valid_Parameters() public void Should_Create_Service_With_Stack_Having_API_Key() { var updateBody = new BulkWorkflowUpdateBody(); - // 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 BulkWorkflowUpdateService(serializer, stack, updateBody); @@ -94,8 +94,7 @@ public void Should_Create_Service_With_Stack_Having_Branch_Uid() public void Should_Create_Service_With_All_Stack_Parameters() { var updateBody = new BulkWorkflowUpdateBody(); - // 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); diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/User/LoginServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/User/LoginServiceTest.cs index 8af49f9..e437e75 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/User/LoginServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/User/LoginServiceTest.cs @@ -1,4 +1,5 @@ -using System; +using Contentstack.Management.Core.Unit.Tests.Helpers; +using System; using System.Net; using System.Net.Http; using System.Text; @@ -13,7 +14,9 @@ namespace Contentstack.Management.Core.Unit.Tests.Core.Services.User [TestClass] public class LoginServiceTest { - ICredentials credentials = new NetworkCredential("name", "password"); + static readonly string Username = TestSecrets.Username; + static readonly string Password = TestSecrets.Password; + ICredentials credentials = new NetworkCredential(Username, Password); JsonSerializerOptions serializerOptions = new JsonSerializerOptions(); [TestMethod] @@ -37,7 +40,7 @@ public void Should_Allow_Credentials() Assert.IsNotNull(loginService); Assert.AreEqual("POST", loginService.HttpMethod); Assert.AreEqual("user-session", loginService.ResourcePath); - Assert.AreEqual("{\"user\":{\"email\":\"name\",\"password\":\"password\"}}", Encoding.Default.GetString(loginService.ByteContent)); + Assert.AreEqual("{\"user\":{\"email\":\"" + Username + "\",\"password\":\"" + Password + "\"}}", Encoding.Default.GetString(loginService.ByteContent)); } [TestMethod] @@ -47,22 +50,22 @@ public void Should_Allow_Credentials_With_Token() loginService.ContentBody(); Assert.IsNotNull(loginService); - Assert.AreEqual("{\"user\":{\"email\":\"name\",\"password\":\"password\",\"tfa_token\":\"token\"}}", Encoding.Default.GetString(loginService.ByteContent)); + Assert.AreEqual("{\"user\":{\"email\":\"" + Username + "\",\"password\":\"" + Password + "\",\"tfa_token\":\"token\"}}", Encoding.Default.GetString(loginService.ByteContent)); } [TestMethod] public void Should_Allow_Credentials_With_MfaSecret() { - string testMfaSecret = "JBSWY3DPEHPK3PXP"; // Base32 encoded "Hello!" + string testMfaSecret = TestSecrets.Base32Secret(); // Base32 encoded "Hello!" var loginService = new LoginService(serializerOptions, credentials, null, testMfaSecret); loginService.ContentBody(); Assert.IsNotNull(loginService); var contentString = Encoding.Default.GetString(loginService.ByteContent); - Assert.IsTrue(contentString.Contains("\"email\":\"name\"")); - Assert.IsTrue(contentString.Contains("\"password\":\"password\"")); + Assert.IsTrue(contentString.Contains("\"email\":\"" + Username + "\"")); + Assert.IsTrue(contentString.Contains("\"password\":\"" + Password + "\"")); Assert.IsTrue(contentString.Contains("\"tfa_token\":")); // Verify the tfa_token is not null or empty in the JSON @@ -73,7 +76,7 @@ public void Should_Allow_Credentials_With_MfaSecret() [TestMethod] public void Should_Generate_TOTP_Token_When_MfaSecret_Provided() { - string testMfaSecret = "JBSWY3DPEHPK3PXP"; // Base32 encoded "Hello!" + string testMfaSecret = TestSecrets.Base32Secret(); // Base32 encoded "Hello!" var loginService1 = new LoginService(serializerOptions, credentials, null, testMfaSecret); var loginService2 = new LoginService(serializerOptions, credentials, null, testMfaSecret); @@ -102,8 +105,7 @@ public void Should_Generate_TOTP_Token_When_MfaSecret_Provided() [TestMethod] public void Should_Prefer_Explicit_Token_Over_MfaSecret() { - string testMfaSecret = "JBSWY3DPEHPK3PXP"; - // file deepcode ignore NoHardcodedCredentials/test: random test token + string testMfaSecret = TestSecrets.Base32Secret(); string explicitToken = "123456"; var loginService = new LoginService(serializerOptions, credentials, explicitToken, testMfaSecret); @@ -120,7 +122,7 @@ public void Should_Prefer_Explicit_Token_Over_MfaSecret() public void Should_Throw_Exception_For_Invalid_Base32_MfaSecret() { // Invalid Base32 secret (contains invalid characters) - string invalidMfaSecret = "INVALID_BASE32_123!@#"; + string invalidMfaSecret = TestSecrets.InvalidBase32Secret(); var loginService = new LoginService(serializerOptions, credentials, null, invalidMfaSecret); } @@ -135,7 +137,7 @@ public void Should_Not_Generate_Token_When_MfaSecret_Is_Empty() // Should not contain tfa_token when MFA secret is empty Assert.IsFalse(contentString.Contains("\"tfa_token\":")); - Assert.AreEqual("{\"user\":{\"email\":\"name\",\"password\":\"password\"}}", contentString); + Assert.AreEqual("{\"user\":{\"email\":\"" + Username + "\",\"password\":\"" + Password + "\"}}", contentString); } [TestMethod] @@ -148,7 +150,7 @@ public void Should_Not_Generate_Token_When_MfaSecret_Is_Null() // Should not contain tfa_token when MFA secret is null Assert.IsFalse(contentString.Contains("\"tfa_token\":")); - Assert.AreEqual("{\"user\":{\"email\":\"name\",\"password\":\"password\"}}", contentString); + Assert.AreEqual("{\"user\":{\"email\":\"" + Username + "\",\"password\":\"" + Password + "\"}}", contentString); } [TestMethod] diff --git a/Contentstack.Management.Core.Unit.Tests/Helpers/TestSecrets.cs b/Contentstack.Management.Core.Unit.Tests/Helpers/TestSecrets.cs new file mode 100644 index 0000000..6af8e8e --- /dev/null +++ b/Contentstack.Management.Core.Unit.Tests/Helpers/TestSecrets.cs @@ -0,0 +1,39 @@ +using System; +using System.Linq; +using System.Security.Cryptography; + +namespace Contentstack.Management.Core.Unit.Tests.Helpers +{ + /// + /// Per-run generated values for tests that need credential-shaped inputs but must not + /// commit literal secrets. None of these are real credentials. + /// + 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"); + + /// A stack API key-shaped value (blt + hex) that does not exist on any stack. + public static string BltKey() => "blt" + Guid.NewGuid().ToString("N").Substring(0, 16); + + /// A valid RFC 4648 base32 string, suitable as a TOTP secret. + public static string Base32Secret() + { + var bytes = new byte[10]; + RandomNumberGenerator.Fill(bytes); + return new string(bytes.Select(b => Base32Alphabet[b % 32]).ToArray()); + } + + /// A string that is not valid base32 (contains characters outside the alphabet). + public static string InvalidBase32Secret() => "!@#" + Guid.NewGuid().ToString("N"); + + /// Alternates upper/lower case; used to check case-insensitive secret handling. + public static string MixedCase(string value) => + new string(value.Select((c, i) => i % 2 == 0 ? char.ToUpperInvariant(c) : char.ToLowerInvariant(c)).ToArray()); + } +} diff --git a/Contentstack.Management.Core.Unit.Tests/Models/UserTest.cs b/Contentstack.Management.Core.Unit.Tests/Models/UserTest.cs index e186c63..382faa8 100644 --- a/Contentstack.Management.Core.Unit.Tests/Models/UserTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Models/UserTest.cs @@ -1,4 +1,5 @@ -using System; +using Contentstack.Management.Core.Unit.Tests.Helpers; +using System; using System.Net; using AutoFixture; using Contentstack.Management.Core.Models; @@ -11,8 +12,7 @@ namespace Contentstack.Management.Core.Unit.Tests.Models public class UserTest { private ContentstackClient client; - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - private readonly NetworkCredential credentials = new NetworkCredential("mock_user", "mock_pasword"); + private readonly NetworkCredential credentials = new NetworkCredential(TestSecrets.Username, TestSecrets.Password); private readonly IFixture _fixture = new Fixture(); [TestInitialize] diff --git a/Contentstack.Management.Core.Unit.Tests/OAuth/OAuthHandlerTest.cs b/Contentstack.Management.Core.Unit.Tests/OAuth/OAuthHandlerTest.cs index ca13db8..fb6eaab 100644 --- a/Contentstack.Management.Core.Unit.Tests/OAuth/OAuthHandlerTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/OAuth/OAuthHandlerTest.cs @@ -1,3 +1,4 @@ +using Contentstack.Management.Core.Unit.Tests.Helpers; using System; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -215,8 +216,7 @@ public void OAuthHandler_AuthorizeAsync_WithTraditionalOAuth_ShouldReturnValidUr ClientId = "test-client-id", RedirectUri = "https://example.com/callback", ResponseType = "code", - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - ClientSecret = "test-secret" + ClientSecret = TestSecrets.Token() }; var handler = new OAuthHandler(_client, traditionalOptions); var authUrl = handler.AuthorizeAsync().Result; diff --git a/Contentstack.Management.Core.Unit.Tests/OAuth/OAuthOptionsTest.cs b/Contentstack.Management.Core.Unit.Tests/OAuth/OAuthOptionsTest.cs index a10718e..174cc2d 100644 --- a/Contentstack.Management.Core.Unit.Tests/OAuth/OAuthOptionsTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/OAuth/OAuthOptionsTest.cs @@ -1,3 +1,4 @@ +using Contentstack.Management.Core.Unit.Tests.Helpers; using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Contentstack.Management.Core.Models; @@ -49,8 +50,7 @@ public void OAuthOptions_IsValid_WithValidTraditionalOAuthOptions_ShouldReturnTr ClientId = "test-client-id", RedirectUri = "https://example.com/callback", ResponseType = "code", - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - ClientSecret = "test-secret" + ClientSecret = TestSecrets.Token() // UsePkce is automatically false when ClientSecret is provided }; var isValid = options.IsValid(); diff --git a/Contentstack.Management.Core.Unit.Tests/OAuth/OAuthTokenTest.cs b/Contentstack.Management.Core.Unit.Tests/OAuth/OAuthTokenTest.cs index 4579143..aa24c42 100644 --- a/Contentstack.Management.Core.Unit.Tests/OAuth/OAuthTokenTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/OAuth/OAuthTokenTest.cs @@ -1,3 +1,4 @@ +using Contentstack.Management.Core.Unit.Tests.Helpers; using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Contentstack.Management.Core.Models; @@ -242,8 +243,7 @@ public void OAuthTokens_ToString_ShouldReturnTypeName() public void OAuthTokens_WithAllProperties_ShouldSetCorrectly() { - // deepcode ignore NoHardcodedCredentials: test fixture value, not a real secret - var accessToken = "test-access-token"; + var accessToken = TestSecrets.Token(); var refreshToken = "test-refresh-token"; var organizationUid = "test-org-uid"; var userUid = "test-user-uid";