Skip to content

Commit 91b83b5

Browse files
reeshika-hclaude
andcommitted
Fix: use approved placeholder
Replace hardcoded passwords and secrets in tests with env/cred-helper values or per-run generated values, and drop the deepcode ignore suppression comments. Clears the Snyk Code NoHardcodedPasswords and HardcodedNonCryptoSecret findings. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 7f81b09 commit 91b83b5

5 files changed

Lines changed: 19 additions & 27 deletions

File tree

‎tests/api/users/test_api.py‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ def test_active_user(self):
4444
"user": {
4545
"first_name": "your_first_name",
4646
"last_name": "your_last_name",
47-
# deepcode ignore NoHardcodedPasswords: test fixture value, not a real secret
48-
"password": "your_password",
49-
# deepcode ignore NoHardcodedPasswords: test fixture value, not a real secret
50-
"password_confirmation": "confirm_your_password"
47+
"password": password,
48+
"password_confirmation": password
5149
}
5250
}
5351
response = self.client.user().activate(activation_token, act_data)
@@ -80,10 +78,8 @@ def test_reset_password(self):
8078
act_data = {
8179
"user": {
8280
"reset_password_token": "abcdefghijklmnop1234567890",
83-
# deepcode ignore NoHardcodedPasswords: test fixture value, not a real secret
84-
"password": "Simple@123",
85-
# deepcode ignore NoHardcodedPasswords: test fixture value, not a real secret
86-
"password_confirmation": "Simple@123"
81+
"password": password,
82+
"password_confirmation": password
8783
}
8884
}
8985
response = self.client.user().reset_password(act_data)

‎tests/integration/api/test_01_user.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
"""User API tests — profile fetch and update."""
22

3+
import os
4+
35
import pytest
46

57
from framework import helpers as h
68

79
pytestmark = pytest.mark.order(1)
810

11+
# Exercised only with bogus tokens; value comes from the environment, no fallback.
12+
TEST_PASSWORD = os.environ.get("TEST_USER_PASSWORD")
13+
914

1015
class TestUser:
1116
def test_fetch(self, ctx):
@@ -26,14 +31,12 @@ class TestUserAuthOps:
2631
"""Account auth endpoints exercised safely (bogus tokens / non-real email)."""
2732

2833
def test_activate_bogus_token(self, ctx):
29-
# deepcode ignore NoHardcodedPasswords: test fixture value, not a real secret
30-
resp = ctx.client.user().activate("bogus_activation_token", {"user": {"password": "Test@12345"}})
34+
resp = ctx.client.user().activate("bogus_activation_token", {"user": {"password": TEST_PASSWORD}})
3135
h.assert_status(resp, 400, 404, 422)
3236

3337
def test_reset_password_bogus_token(self, ctx):
3438
resp = ctx.client.user().reset_password(
35-
# deepcode ignore NoHardcodedPasswords: test fixture value, not a real secret
36-
{"user": {"reset_password_token": "bogus", "password": "Test@12345", "password_confirmation": "Test@12345"}}
39+
{"user": {"reset_password_token": "bogus", "password": TEST_PASSWORD, "password_confirmation": TEST_PASSWORD}}
3740
)
3841
h.assert_status(resp, 400, 404, 422)
3942

‎tests/mock/users/test_mock.py‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ def test_mock_active_user(self):
3838
"user": {
3939
"first_name": "your_first_name",
4040
"last_name": "your_last_name",
41-
# deepcode ignore NoHardcodedPasswords: test fixture value, not a real secret
42-
"password": "your_password",
43-
# deepcode ignore NoHardcodedPasswords: test fixture value, not a real secret
44-
"password_confirmation": "confirm_your_password"
41+
"password": password,
42+
"password_confirmation": password
4543
}
4644
}
4745

@@ -81,10 +79,8 @@ def test_reset_password(self):
8179
act_data = {
8280
"user": {
8381
"reset_password_token": "abcdefghijklmnop1234567890",
84-
# deepcode ignore NoHardcodedPasswords: test fixture value, not a real secret
85-
"password": "Simple@123",
86-
# deepcode ignore NoHardcodedPasswords: test fixture value, not a real secret
87-
"password_confirmation": "Simple@123"
82+
"password": password,
83+
"password_confirmation": password
8884
}
8985
}
9086
response = self.client.user().reset_password(act_data).json()

‎tests/unit/contentstack/test_totp_login.py‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base64
12
import unittest
23
import os
34
import sys
@@ -18,8 +19,7 @@ def setUp(self):
1819
self.client = Client()
1920
self.test_email = "test@example.com"
2021
self.test_password = "test_password"
21-
# deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
22-
self.test_secret = "JBSWY3DPEHPK3PXP" # Standard test secret for TOTP
22+
self.test_secret = base64.b32encode(os.urandom(10)).decode() # Valid base32 TOTP secret generated per test run
2323
self.test_tfa_token = "123456"
2424

2525
def tearDown(self):
@@ -38,9 +38,7 @@ def test_login_method_signature_with_totp(self):
3838
# Test that the method accepts TOTP parameters without error
3939
try:
4040
client.login(self.test_email, self.test_password, tfa_token=self.test_tfa_token)
41-
# deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
4241
client.login(self.test_email, self.test_password, mfa_secret=self.test_secret)
43-
# deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
4442
client.login(self.test_email, self.test_password, tfa_token=self.test_tfa_token, mfa_secret=self.test_secret)
4543
except Exception as e:
4644
self.fail(f"Login method should accept TOTP parameters without error: {e}")
@@ -74,7 +72,6 @@ def test_login_with_mfa_secret_generates_totp(self):
7472
result = self.client.login(
7573
self.test_email,
7674
self.test_password,
77-
# deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
7875
mfa_secret=self.test_secret
7976
)
8077

‎tests/unit/test_oauth_handler.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import json
66
import time
77
import unittest
8+
import uuid
89
from unittest.mock import Mock, patch, MagicMock
910
import requests
1011

@@ -19,7 +20,7 @@ def setUp(self):
1920
self.app_id = "test-app-id"
2021
self.client_id = "test-client-id"
2122
self.redirect_uri = "http://localhost:3000/callback"
22-
self.client_secret = "test-client-secret"
23+
self.client_secret = uuid.uuid4().hex # Generated per test run, not a real secret
2324
self.scope = ["read", "write"]
2425
self.api_client = Mock()
2526
self.api_client.headers = {}
@@ -31,7 +32,6 @@ def setUp(self):
3132
app_id=self.app_id,
3233
client_id=self.client_id,
3334
redirect_uri=self.redirect_uri,
34-
# deepcode ignore HardcodedNonCryptoSecret: test fixture value, not a real secret
3535
client_secret=self.client_secret,
3636
scope=self.scope,
3737
api_client=self.api_client

0 commit comments

Comments
 (0)