1
0
Fork 0
mirror of https://github.com/imjasonh/claude-test synced 2026-07-07 00:33:00 +00:00
Signed-off-by: Jason Hall <jason@chainguard.dev>
This commit is contained in:
Jason Hall 2025-08-10 17:49:32 -04:00
parent 719af59d70
commit aaea6bfaf9
Failed to extract signature
4 changed files with 2 additions and 350 deletions

View file

@ -1,27 +0,0 @@
{
"name": "outdated-deps-app",
"version": "1.0.0",
"description": "Testing with minimal deps",
"main": "app.js",
"scripts": {
"start": "node app.js",
"test": "node simple-test.js"
},
"dependencies": {
"express": "3.4.8",
"lodash": "2.4.1",
"moment": "2.8.1",
"async": "0.9.0",
"request": "2.40.0",
"bcryptjs": "2.4.3",
"jsonwebtoken": "5.0.5",
"validator": "3.40.1",
"uuid": "2.0.3",
"chalk": "0.5.1",
"winston": "0.8.3",
"morgan": "1.3.2",
"helmet": "0.4.2",
"cors": "2.4.2",
"compression": "1.0.11"
}
}

View file

@ -4,8 +4,7 @@
"description": "An app with many outdated dependencies",
"main": "app.js",
"scripts": {
"start": "node app.js",
"test": "mocha"
"start": "node app.js"
},
"author": "",
"license": "MIT",
@ -90,4 +89,4 @@
"pm2": "0.10.0",
"forever": "0.11.0"
}
}
}

View file

@ -1,170 +0,0 @@
// Simple test without external dependencies
var http = require('http');
var assert = require('assert');
var testsPassed = 0;
var testsFailed = 0;
function makeRequest(method, path, data, callback) {
var options = {
hostname: 'localhost',
port: 3000,
path: path,
method: method,
headers: {
'Content-Type': 'application/json'
}
};
var req = http.request(options, function(res) {
var body = '';
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
callback(null, res, body);
});
});
req.on('error', callback);
if (data) {
req.write(JSON.stringify(data));
}
req.end();
}
function test(name, fn) {
console.log('Testing: ' + name);
fn(function(err) {
if (err) {
console.log(' ✗ FAILED:', err.message);
testsFailed++;
} else {
console.log(' ✓ PASSED');
testsPassed++;
}
});
}
// Start the server first
var app = require('./app');
var server = app.listen(3000, function() {
console.log('\n=== Running Tests ===\n');
// Run tests sequentially
setTimeout(runTests, 100);
});
function runTests() {
test('GET / should return homepage', function(done) {
makeRequest('GET', '/', null, function(err, res, body) {
if (err) return done(err);
assert.equal(res.statusCode, 200, 'Status should be 200');
assert(body.includes('Outdated Dependencies App'), 'Should contain app title');
done();
});
});
setTimeout(function() {
test('POST /register should create user', function(done) {
makeRequest('POST', '/register', {
email: 'test@example.com',
password: 'password123'
}, function(err, res, body) {
if (err) return done(err);
assert.equal(res.statusCode, 200, 'Status should be 200');
var data = JSON.parse(body);
assert.equal(data.message, 'User created', 'Should have success message');
assert(data.token, 'Should have token');
done();
});
});
}, 200);
setTimeout(function() {
test('POST /register with invalid email should fail', function(done) {
makeRequest('POST', '/register', {
email: 'notanemail',
password: 'password123'
}, function(err, res, body) {
if (err) return done(err);
assert.equal(res.statusCode, 400, 'Status should be 400');
var data = JSON.parse(body);
assert.equal(data.error, 'Invalid email', 'Should have error message');
done();
});
});
}, 400);
setTimeout(function() {
test('POST /login with correct credentials', function(done) {
makeRequest('POST', '/login', {
email: 'test@example.com',
password: 'password123'
}, function(err, res, body) {
if (err) return done(err);
assert.equal(res.statusCode, 200, 'Status should be 200');
var data = JSON.parse(body);
assert.equal(data.message, 'Login successful', 'Should have success message');
assert(data.token, 'Should have token');
done();
});
});
}, 600);
setTimeout(function() {
test('POST /login with wrong password', function(done) {
makeRequest('POST', '/login', {
email: 'test@example.com',
password: 'wrongpassword'
}, function(err, res, body) {
if (err) return done(err);
assert.equal(res.statusCode, 401, 'Status should be 401');
var data = JSON.parse(body);
assert.equal(data.error, 'Invalid password', 'Should have error message');
done();
});
});
}, 800);
setTimeout(function() {
test('GET /users should return users', function(done) {
makeRequest('GET', '/users', null, function(err, res, body) {
if (err) return done(err);
assert.equal(res.statusCode, 200, 'Status should be 200');
var data = JSON.parse(body);
assert(Array.isArray(data), 'Should be an array');
assert(data.length > 0, 'Should have at least one user');
assert(!data[0].password, 'Should not include password');
done();
});
});
}, 1000);
setTimeout(function() {
test('GET /info should return system info', function(done) {
makeRequest('GET', '/info', null, function(err, res, body) {
if (err) return done(err);
assert.equal(res.statusCode, 200, 'Status should be 200');
var data = JSON.parse(body);
assert(data.uptime, 'Should have uptime');
assert(data.memory, 'Should have memory info');
assert(data.nodeVersion, 'Should have node version');
assert(Array.isArray(data.dependencies), 'Should have dependencies array');
done();
});
});
}, 1200);
// Print results and exit
setTimeout(function() {
console.log('\n=== Test Results ===');
console.log('Passed:', testsPassed);
console.log('Failed:', testsFailed);
console.log('Total:', testsPassed + testsFailed);
server.close();
process.exit(testsFailed > 0 ? 1 : 0);
}, 1500);
}

150
test.js
View file

@ -1,150 +0,0 @@
var request = require('supertest');
var chai = require('chai');
var expect = chai.expect;
var app = require('./app');
describe('Outdated App Tests', function() {
describe('GET /', function() {
it('should return homepage with status 200', function(done) {
request(app)
.get('/')
.expect(200)
.end(function(err, res) {
if (err) return done(err);
expect(res.text).to.include('Outdated Dependencies App');
expect(res.text).to.include('Session ID');
done();
});
});
});
describe('POST /register', function() {
it('should register a new user', function(done) {
request(app)
.post('/register')
.send({ email: 'test@example.com', password: 'password123' })
.expect(200)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.have.property('message', 'User created');
expect(res.body).to.have.property('token');
expect(res.body.user).to.have.property('email', 'test@example.com');
expect(res.body.user).to.not.have.property('password');
done();
});
});
it('should reject invalid email', function(done) {
request(app)
.post('/register')
.send({ email: 'notanemail', password: 'password123' })
.expect(400)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.have.property('error', 'Invalid email');
done();
});
});
});
describe('POST /login', function() {
before(function(done) {
// Register a user first
request(app)
.post('/register')
.send({ email: 'login@example.com', password: 'testpass' })
.end(done);
});
it('should login with correct credentials', function(done) {
request(app)
.post('/login')
.send({ email: 'login@example.com', password: 'testpass' })
.expect(200)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.have.property('message', 'Login successful');
expect(res.body).to.have.property('token');
expect(res.body.user).to.have.property('email', 'login@example.com');
done();
});
});
it('should reject wrong password', function(done) {
request(app)
.post('/login')
.send({ email: 'login@example.com', password: 'wrongpass' })
.expect(401)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.have.property('error', 'Invalid password');
done();
});
});
it('should reject non-existent user', function(done) {
request(app)
.post('/login')
.send({ email: 'nobody@example.com', password: 'anypass' })
.expect(404)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.have.property('error', 'User not found');
done();
});
});
});
describe('GET /users', function() {
it('should return all users without passwords', function(done) {
request(app)
.get('/users')
.expect(200)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.be.an('array');
res.body.forEach(function(user) {
expect(user).to.not.have.property('password');
expect(user).to.have.property('email');
});
done();
});
});
});
describe('GET /info', function() {
it('should return system information', function(done) {
request(app)
.get('/info')
.expect(200)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.have.property('uptime');
expect(res.body).to.have.property('memory');
expect(res.body).to.have.property('nodeVersion');
expect(res.body).to.have.property('platform');
expect(res.body).to.have.property('dependencies');
expect(res.body.dependencies).to.be.an('array');
expect(res.body.dependencies.length).to.be.above(50);
done();
});
});
});
describe('GET /external-data', function() {
it('should return external data with timestamp', function(done) {
this.timeout(5000); // Allow more time for external API call
request(app)
.get('/external-data')
.expect(200)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.have.property('timestamp');
expect(res.body).to.have.property('data');
expect(res.body.data).to.be.an('array');
done();
});
});
});
});