refactor: use python instead of javascript
This commit is contained in:
@@ -27,28 +27,22 @@ git config user.email "user@workshop.local" | Out-Null
|
||||
|
||||
# Create initial application on main
|
||||
$app = @"
|
||||
class Application {
|
||||
constructor() {
|
||||
this.name = 'MyApp';
|
||||
this.version = '1.0.0';
|
||||
}
|
||||
class Application:
|
||||
def __init__(self):
|
||||
self.name = 'MyApp'
|
||||
self.version = '1.0.0'
|
||||
|
||||
start() {
|
||||
console.log('Application started');
|
||||
this.authenticate();
|
||||
}
|
||||
def start(self):
|
||||
print('Application started')
|
||||
self.authenticate()
|
||||
|
||||
authenticate() {
|
||||
console.log('Authentication check');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Application;
|
||||
def authenticate(self):
|
||||
print('Authentication check')
|
||||
return True
|
||||
"@
|
||||
|
||||
Set-Content -Path "app.js" -Value $app
|
||||
git add app.js
|
||||
Set-Content -Path "app.py" -Value $app
|
||||
git add app.py
|
||||
git commit -m "Initial application" | Out-Null
|
||||
|
||||
$readme = @"
|
||||
@@ -66,54 +60,44 @@ git checkout -b feature-login | Out-Null
|
||||
|
||||
# Start working on login feature
|
||||
$loginInitial = @"
|
||||
class LoginService {
|
||||
constructor() {
|
||||
this.users = new Map();
|
||||
}
|
||||
from datetime import datetime
|
||||
|
||||
register(username, password) {
|
||||
if (this.users.has(username)) {
|
||||
throw new Error('User already exists');
|
||||
}
|
||||
this.users.set(username, { password, createdAt: new Date() });
|
||||
return true;
|
||||
}
|
||||
}
|
||||
class LoginService:
|
||||
def __init__(self):
|
||||
self.users = {}
|
||||
|
||||
module.exports = LoginService;
|
||||
def register(self, username, password):
|
||||
if username in self.users:
|
||||
raise ValueError('User already exists')
|
||||
self.users[username] = {'password': password, 'created_at': datetime.now()}
|
||||
return True
|
||||
"@
|
||||
|
||||
Set-Content -Path "login.js" -Value $loginInitial
|
||||
git add login.js
|
||||
Set-Content -Path "login.py" -Value $loginInitial
|
||||
git add login.py
|
||||
git commit -m "Start login service implementation" | Out-Null
|
||||
|
||||
# Add a critical bug to main branch (simulating a bug that was introduced)
|
||||
git checkout main | Out-Null
|
||||
|
||||
$appWithBug = @"
|
||||
class Application {
|
||||
constructor() {
|
||||
this.name = 'MyApp';
|
||||
this.version = '1.0.0';
|
||||
}
|
||||
class Application:
|
||||
def __init__(self):
|
||||
self.name = 'MyApp'
|
||||
self.version = '1.0.0'
|
||||
|
||||
start() {
|
||||
console.log('Application started');
|
||||
this.authenticate();
|
||||
}
|
||||
def start(self):
|
||||
print('Application started')
|
||||
self.authenticate()
|
||||
|
||||
authenticate() {
|
||||
console.log('Authentication check');
|
||||
// BUG: This allows unauthenticated access!
|
||||
return true; // Should check actual credentials
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Application;
|
||||
def authenticate(self):
|
||||
print('Authentication check')
|
||||
# BUG: This allows unauthenticated access!
|
||||
return True # Should check actual credentials
|
||||
"@
|
||||
|
||||
Set-Content -Path "app.js" -Value $appWithBug
|
||||
git add app.js
|
||||
Set-Content -Path "app.py" -Value $appWithBug
|
||||
git add app.py
|
||||
git commit -m "Update authentication (contains bug)" | Out-Null
|
||||
|
||||
# Go back to feature branch
|
||||
@@ -121,35 +105,29 @@ git checkout feature-login | Out-Null
|
||||
|
||||
# Create work in progress (uncommitted changes)
|
||||
$loginWIP = @"
|
||||
class LoginService {
|
||||
constructor() {
|
||||
this.users = new Map();
|
||||
}
|
||||
from datetime import datetime
|
||||
|
||||
register(username, password) {
|
||||
if (this.users.has(username)) {
|
||||
throw new Error('User already exists');
|
||||
}
|
||||
this.users.set(username, { password, createdAt: new Date() });
|
||||
return true;
|
||||
}
|
||||
class LoginService:
|
||||
def __init__(self):
|
||||
self.users = {}
|
||||
|
||||
// TODO: Complete this method
|
||||
login(username, password) {
|
||||
if (!this.users.has(username)) {
|
||||
throw new Error('User not found');
|
||||
}
|
||||
// TODO: Verify password
|
||||
// TODO: Return user session
|
||||
}
|
||||
def register(self, username, password):
|
||||
if username in self.users:
|
||||
raise ValueError('User already exists')
|
||||
self.users[username] = {'password': password, 'created_at': datetime.now()}
|
||||
return True
|
||||
|
||||
// TODO: Add logout method
|
||||
}
|
||||
# TODO: Complete this method
|
||||
def login(self, username, password):
|
||||
if username not in self.users:
|
||||
raise ValueError('User not found')
|
||||
# TODO: Verify password
|
||||
# TODO: Return user session
|
||||
|
||||
module.exports = LoginService;
|
||||
# TODO: Add logout method
|
||||
"@
|
||||
|
||||
Set-Content -Path "login.js" -Value $loginWIP
|
||||
Set-Content -Path "login.py" -Value $loginWIP
|
||||
|
||||
# Don't commit - leave as uncommitted changes
|
||||
|
||||
@@ -169,10 +147,10 @@ Write-Host "1. Navigate to the challenge directory: cd challenge" -ForegroundCol
|
||||
Write-Host "2. Check your status: git status (see uncommitted changes)" -ForegroundColor White
|
||||
Write-Host "3. Stash your work: git stash save 'WIP: login feature'" -ForegroundColor White
|
||||
Write-Host "4. Switch to main: git checkout main" -ForegroundColor White
|
||||
Write-Host "5. Fix the security bug in app.js (remove the comment and fix the auth)" -ForegroundColor White
|
||||
Write-Host "6. Commit the fix: git add app.js && git commit -m 'Fix critical security bug'" -ForegroundColor White
|
||||
Write-Host "5. Fix the security bug in app.py (remove the comment and fix the auth)" -ForegroundColor White
|
||||
Write-Host "6. Commit the fix: git add app.py && git commit -m 'Fix critical security bug'" -ForegroundColor White
|
||||
Write-Host "7. Switch back: git checkout feature-login" -ForegroundColor White
|
||||
Write-Host "8. Restore your work: git stash pop" -ForegroundColor White
|
||||
Write-Host "9. Complete the TODOs in login.js" -ForegroundColor White
|
||||
Write-Host "9. Complete the TODOs in login.py" -ForegroundColor White
|
||||
Write-Host "10. Commit your completed feature" -ForegroundColor White
|
||||
Write-Host "`nRun '../verify.ps1' from the challenge directory to check your solution.`n" -ForegroundColor Cyan
|
||||
|
||||
@@ -66,21 +66,21 @@ if ($mainCommits -notmatch "security bug|Fix.*bug|security fix") {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check that app.js has been fixed
|
||||
if (-not (Test-Path "app.js")) {
|
||||
Write-Host "[FAIL] app.js not found on main branch." -ForegroundColor Red
|
||||
# Check that app.py has been fixed
|
||||
if (-not (Test-Path "app.py")) {
|
||||
Write-Host "[FAIL] app.py not found on main branch." -ForegroundColor Red
|
||||
git checkout feature-login 2>$null | Out-Null
|
||||
Set-Location ..
|
||||
exit 1
|
||||
}
|
||||
|
||||
$appContent = Get-Content "app.js" -Raw
|
||||
$appContent = Get-Content "app.py" -Raw
|
||||
|
||||
# The bug was "return true" in authenticate - it should be fixed now
|
||||
# We'll check that the buggy comment is gone or the implementation is improved
|
||||
if ($appContent -match "allows unauthenticated access") {
|
||||
Write-Host "[FAIL] The security bug comment still exists in app.js." -ForegroundColor Red
|
||||
Write-Host "Hint: Remove the bug from app.js and commit the fix" -ForegroundColor Yellow
|
||||
Write-Host "[FAIL] The security bug comment still exists in app.py." -ForegroundColor Red
|
||||
Write-Host "Hint: Remove the bug from app.py and commit the fix" -ForegroundColor Yellow
|
||||
git checkout feature-login 2>$null | Out-Null
|
||||
Set-Location ..
|
||||
exit 1
|
||||
@@ -103,26 +103,26 @@ if ($commitCount -lt 3) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check that login.js exists
|
||||
if (-not (Test-Path "login.js")) {
|
||||
Write-Host "[FAIL] login.js not found on feature-login branch." -ForegroundColor Red
|
||||
# Check that login.py exists
|
||||
if (-not (Test-Path "login.py")) {
|
||||
Write-Host "[FAIL] login.py not found on feature-login branch." -ForegroundColor Red
|
||||
Set-Location ..
|
||||
exit 1
|
||||
}
|
||||
|
||||
$loginContent = Get-Content "login.js" -Raw
|
||||
$loginContent = Get-Content "login.py" -Raw
|
||||
|
||||
# Check that login method exists and is implemented
|
||||
if ($loginContent -notmatch "login\(username, password\)") {
|
||||
Write-Host "[FAIL] login.js should have a login method." -ForegroundColor Red
|
||||
Write-Host "[FAIL] login.py should have a login method." -ForegroundColor Red
|
||||
Set-Location ..
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check that TODOs are completed (no TODO comments should remain)
|
||||
if ($loginContent -match "TODO") {
|
||||
Write-Host "[FAIL] login.js still contains TODO comments." -ForegroundColor Red
|
||||
Write-Host "Hint: Complete all the TODOs in login.js before committing" -ForegroundColor Yellow
|
||||
Write-Host "[FAIL] login.py still contains TODO comments." -ForegroundColor Red
|
||||
Write-Host "Hint: Complete all the TODOs in login.py before committing" -ForegroundColor Yellow
|
||||
Set-Location ..
|
||||
exit 1
|
||||
}
|
||||
@@ -155,7 +155,7 @@ if ($stashCount -gt 0) {
|
||||
|
||||
# Verify the login implementation is complete
|
||||
if ($loginContent -notmatch "logout|session") {
|
||||
Write-Host "[PARTIAL] login.js is missing logout or session functionality." -ForegroundColor Yellow
|
||||
Write-Host "[PARTIAL] login.py is missing logout or session functionality." -ForegroundColor Yellow
|
||||
Write-Host "Consider adding logout method for a complete implementation" -ForegroundColor Yellow
|
||||
# Don't fail - this is just a suggestion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user