Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_project(self):
db = self.application.DBSession()
projects = [
database.Project(name="first project", description=""),
database.Project(name="a test", description="Test project"),
database.Project(name="private P", description="admin can't see"),
database.Project(name="last project", description="Other"),
]
for project in projects:
db.add(project)
db.commit()
for i in [1, 2, 4]:
db.add(database.ProjectMember(
project_id=i,
user_login='admin',
privileges=database.Privileges.ADMIN))
db.commit()
# Authenticate with token
response = self.get('/?token=' + self.application.single_user_token)
self.assertEqual(response.code, 302)
self.assertEqual(response.headers['Location'], '/')
# Check project list
response = self.get('/')
self.assertEqual(response.code, 200)
self.assertIn(b"first project", response.body)
self.assertIn(b"a test", response.body)
self.assertNotIn(b"private P", response.body)
def test_project(self):
db = self.application.DBSession()
projects = [
database.Project(name="first project", description=""),
database.Project(name="a test", description="Test project"),
database.Project(name="private P", description="admin can't see"),
database.Project(name="last project", description="Other"),
]
for project in projects:
db.add(project)
db.commit()
for i in [1, 2, 4]:
db.add(database.ProjectMember(
project_id=i,
user_login='admin',
privileges=database.Privileges.ADMIN))
db.commit()
# Authenticate with token
response = self.get('/?token=' + self.application.single_user_token)
self.assertEqual(response.code, 302)
self.assertEqual(response.headers['Location'], '/')
def test_project(self):
db = self.application.DBSession()
projects = [
database.Project(name="first project", description=""),
database.Project(name="a test", description="Test project"),
database.Project(name="private P", description="admin can't see"),
database.Project(name="last project", description="Other"),
]
for project in projects:
db.add(project)
db.commit()
for i in [1, 2, 4]:
db.add(database.ProjectMember(
project_id=i,
user_login='admin',
privileges=database.Privileges.ADMIN))
db.commit()
# Authenticate with token
response = self.get('/?token=' + self.application.single_user_token)
def test_project(self):
db = self.application.DBSession()
projects = [
database.Project(name="first project", description=""),
database.Project(name="a test", description="Test project"),
database.Project(name="private P", description="admin can't see"),
database.Project(name="last project", description="Other"),
]
for project in projects:
db.add(project)
db.commit()
for i in [1, 2, 4]:
db.add(database.ProjectMember(
project_id=i,
user_login='admin',
privileges=database.Privileges.ADMIN))
db.commit()
# Authenticate with token
response = self.get('/?token=' + self.application.single_user_token)
self.assertEqual(response.code, 302)
self.assertEqual(response.headers['Location'], '/')
# Check project list
response = self.get('/')
self.assertEqual(response.code, 200)
self.assertIn(b"first project", response.body)
self.assertIn(b"a test", response.body)
self.assertNotIn(b"private P", response.body)
self.assertIn(b"last project", response.body)
def tearDown(self):
close_all_sessions()
engine = create_engine(DATABASE_URI)
database.Base.metadata.drop_all(bind=engine)
response = self.post('/register', dict(login='User',
password1='hackme',
password2='hackme',
email='test@example.com'))
self.assertEqual(response.code, 302)
self.assertEqual(response.headers['Location'], '/')
# User exists in database
db = self.application.DBSession()
self.assertEqual(
[
(
user.login,
bool(user.hashed_password), bool(user.password_set_date),
)
for user in db.query(database.User).all()
],
[
('admin', True, True),
('user', True, True),
],
)
# Log out
response = self.get('/logout')
self.assertEqual(response.code, 302)
self.assertEqual(response.headers['Location'], '/')
# Wait so that reset link is more recent than password
time.sleep(1)
# Send reset link
def test_filename(self):
validate.filename.windows = True # escape device names
self.assertEqual(validate.filename('/etc/passwd'), 'passwd')
self.assertEqual(validate.filename('/etc/passwd.txt'), 'passwd.txt')
self.assertEqual(validate.filename('ééé'), '_')
self.assertEqual(validate.filename('ééé.pdf'), '_.pdf')
self.assertEqual(validate.filename('/tmp/NUL.pdf'), '_NUL.pdf')
self.assertEqual(validate.filename('/tmp/nul.pdf'), '_nul.pdf')
{'document_add': [{'description': '', 'id': 1, 'name': name}],
'id': 3})
poll_proj1 = self.poll_event(1, 3)
# Create document 2 in project 2
response = await self.apost('/api/project/2/document/new',
dict(name='otherdoc',
description='Other one'),
fmt='multipart',
files=dict(file=('../otherdoc.html',
'text/plain',
b'different content')))
self.assertEqual(response.code, 200)
self.assertEqual(response.body, b'{"created": 2}')
db = self.application.DBSession()
doc = db.query(database.Document).get(2)
self.assertEqual(doc.name, 'otherdoc')
self.assertEqual(doc.description, 'Other one')
self.assertEqual(doc.filename, 'otherdoc.html')
self.assertEqual(
await poll_proj2,
{'document_add': [{'description': 'Other one', 'id': 2,
'name': 'otherdoc'}], 'id': 4})
poll_proj2 = self.poll_event(2, 4)
# Create highlight 1 in document 1
response = await self.apost('/api/project/1/document/1/highlight/new',
dict(start_offset=3, end_offset=7,
tags=[1]),
fmt='json')
self.assertEqual(response.code, 200)
self.assertEqual(response.body, b'{"id": 1}')
body = (
b"\n"
b"\n \n <title>Test</title>\n\n"
b"<h1>Example</h1><p>This is an <a>example</a> text document.\n"
b"It should be <blink>converted</blink>.</p>\n\n"
b"<p>It has another paragraph <strong>here</strong>, "
b"images: <img src="\"here.png\"" width="\"50\""> "
b"<img width="\"30\"" src="\"/over/there.png\"" title="\"important\""> "
b"<img class="\"a\"" src="\"http://and/the/last/one.png\"">, and "
b"links: <a href="\"here\"">1</a> "
b"<a href="\"/over/there\"" title="\"important\"">2</a> "
b"<a class="\"a\"" href="\"http://and/the/last/one\"">3</a></p>\n"
b"\n"
)
with mock.patch('tornado.process.Subprocess', object()):
body = await convert.to_html(body, 'text/html', 'test.html',
self.config)
self.assertEqual(
body,
"<h1>Example</h1><p>This is an example text document.\n"
"It should be converted.</p>\n\n"
def test_filename(self):
validate.filename.windows = True # escape device names
self.assertEqual(validate.filename('/etc/passwd'), 'passwd')
self.assertEqual(validate.filename('/etc/passwd.txt'), 'passwd.txt')
self.assertEqual(validate.filename('ééé'), '_')
self.assertEqual(validate.filename('ééé.pdf'), '_.pdf')
self.assertEqual(validate.filename('/tmp/NUL.pdf'), '_NUL.pdf')
self.assertEqual(validate.filename('/tmp/nul.pdf'), '_nul.pdf')