Skip to content

Commit d5b03a2

Browse files
committed
fix: Update Strava cookie format to semicolon-delimited string
- Changed STRAVA_COOKIES from JSON to semicolon-delimited string format - Updated cookie parsing to handle browser-native format: 'key1=value1; key2=value2' - Enhanced error messages with expected format examples - Added cookie count logging for debugging - Updated documentation with correct cookie examples This matches the actual cookie format copied from browser DevTools, making it easier for users to set up integration tests.
1 parent 608090a commit d5b03a2

2 files changed

Lines changed: 40 additions & 29 deletions

File tree

docs/STRAVA_INTEGRATION_TESTING.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,29 @@ This project includes both **unit tests** (mocked) and **optional integration te
2222

2323
## Running Integration Tests
2424

25-
### Option 1: Environment Variables
25+
### Option 1: Environment Variables (Temporary)
2626

2727
```bash
28-
# Set credentials as environment variables
29-
export STRAVA_COOKIES='{"strava_session": "your_session_cookie"}'
30-
export STRAVA_TOKEN='your_csrf_token'
28+
# Set credentials for this session (cookie string format from browser)
29+
export STRAVA_COOKIES='_strava4_session=your_session_value; other_cookie=value'
30+
export STRAVA_TOKEN='your_csrf_token_here'
3131

3232
# Run integration tests
3333
pytest -v -m requires_strava_auth
3434
```
3535

36-
### Option 2: Hardcoded Test Credentials (Development)
36+
### Option 2: Environment Variables in .env File (Local Development)
3737

38-
Edit `neural_engine/tests/conftest.py` and add:
39-
40-
```python
41-
# conftest.py
42-
import os
43-
44-
# Optional: Add your real Strava credentials here for local testing
45-
# WARNING: Don't commit real credentials! Add conftest.py to .gitignore
46-
TEST_STRAVA_COOKIES = os.getenv('STRAVA_COOKIES', None)
47-
TEST_STRAVA_TOKEN = os.getenv('STRAVA_TOKEN', None)
38+
```bash
39+
# Create .env file (add to .gitignore!)
40+
cat > .env << 'EOF'
41+
STRAVA_COOKIES='_strava4_session=your_session_value; other_cookie=value'
42+
STRAVA_TOKEN='your_csrf_token'
43+
EOF
44+
45+
# Load and run tests
46+
source .env
47+
pytest -v -m requires_strava_auth
4848
```
4949

5050
### Option 3: Store in KeyValueStore (Persistent)
@@ -54,7 +54,8 @@ TEST_STRAVA_TOKEN = os.getenv('STRAVA_TOKEN', None)
5454
python3 -c "
5555
from neural_engine.core.key_value_store import KeyValueStore
5656
kv = KeyValueStore()
57-
kv.set('strava_cookies', {'strava_session': 'your_session_cookie'})
57+
# Store as semicolon-delimited string (as copied from browser)
58+
kv.set('strava_cookies', '_strava4_session=your_session_value; other_cookie=value')
5859
kv.set('strava_token', 'your_csrf_token')
5960
print('Credentials stored!')
6061
"
@@ -87,13 +88,12 @@ pytest -v -m requires_strava_auth
8788

8889
### Example Credentials Format
8990

90-
```json
91-
{
92-
"cookies": {
93-
"strava_session": "ey1234567890abcdef..."
94-
},
95-
"token": "csrf_token_value_here"
96-
}
91+
```bash
92+
# Cookies (semicolon-delimited string as copied from browser)
93+
STRAVA_COOKIES='_strava4_session=a1b2c3d4e5f6...; CloudFront-Policy=eyJ...; CloudFront-Signature=abc...'
94+
95+
# CSRF Token (string)
96+
STRAVA_TOKEN='xyz123abc456...'
9797
```
9898

9999
## Security Notes

neural_engine/tests/test_strava_auth_flow.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,33 @@ def real_credentials(self, kv_store):
167167
1. Environment variables (STRAVA_COOKIES, STRAVA_TOKEN)
168168
2. Existing KeyValueStore credentials
169169
3. Skip test if neither available
170+
171+
STRAVA_COOKIES format: Semicolon-delimited string as copied from browser
172+
Example: '_strava4_session=abc123; CloudFront-Policy=xyz; CloudFront-Signature=def'
170173
"""
171174
# Try environment variables first
172175
cookies_env = os.getenv('STRAVA_COOKIES')
173176
token_env = os.getenv('STRAVA_TOKEN')
174177

175178
if cookies_env and token_env:
176-
# Parse JSON from environment
179+
# Parse semicolon-delimited cookie string into dict
177180
try:
178-
cookies = json.loads(cookies_env) if isinstance(cookies_env, str) else cookies_env
181+
cookies = {}
182+
for cookie_pair in cookies_env.split(';'):
183+
cookie_pair = cookie_pair.strip()
184+
if '=' in cookie_pair:
185+
key, value = cookie_pair.split('=', 1)
186+
cookies[key.strip()] = value.strip()
187+
188+
if not cookies:
189+
pytest.skip("STRAVA_COOKIES is empty or invalid format. Expected: 'key1=value1; key2=value2'")
190+
179191
kv_store.set("strava_cookies", cookies)
180192
kv_store.set("strava_token", token_env)
181193
print(f"\n✓ Using Strava credentials from environment variables")
182-
except json.JSONDecodeError as e:
183-
pytest.skip(f"Invalid JSON in STRAVA_COOKIES environment variable: {e}")
194+
print(f" Parsed {len(cookies)} cookie(s): {list(cookies.keys())}")
195+
except Exception as e:
196+
pytest.skip(f"Failed to parse STRAVA_COOKIES: {e}. Expected format: 'key1=value1; key2=value2'")
184197
else:
185198
# Try existing credentials in KeyValueStore
186199
existing_cookies = kv_store.get("strava_cookies")
@@ -190,8 +203,6 @@ def real_credentials(self, kv_store):
190203
print(f"\n✓ Using existing Strava credentials from KeyValueStore")
191204
else:
192205
pytest.skip(
193-
"Real Strava credentials not provided. "
194-
"Set STRAVA_COOKIES and STRAVA_TOKEN environment variables, "
195206
"Real Strava credentials not provided. "
196207
"Set STRAVA_COOKIES and STRAVA_TOKEN environment variables, "
197208
"or see docs/STRAVA_INTEGRATION_TESTING.md for setup instructions."

0 commit comments

Comments
 (0)