/usr/share/pyshared/mumble/tests.py is in python-django-mumble 2.10-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | # -*- coding: utf-8 -*-
# kate: space-indent on; indent-width 4; replace-tabs on;
"""
* Copyright © 2009-2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
*
* Mumble-Django is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
"""
# Privs:
#
# Unauthed users:
# * Registration: no Anon_MumbleUser{,Link}FormTestCase
# * Administration: no Anon_MumbleFormTestCase
# * User texture: no
# * User list: no
# * Log messages: no
# * Instance scope: ALL
#
# Authed users, unregistered:
# * Registration: self, User{,Password,Link}Form User_MumbleUserLinkFormTestCase
# * Administration: no
# * User texture: no
# * User list: no
# * Log messages: no
# * Instance scope: CURRENT
#
# Authed users, not admins:
# * Registration: self, UserForm
# * Administration: no
# * User texture: self
# * User list: no
# * Log messages: no
# * Instance scope: CURRENT
#
# Authed users, admins:
# * Registration: everyone
# * Administration: yes
# * User texture: everyone
# * User list: yes
# * Log messages: yes
# * Instance scope: CURRENT
#
# Authed users, superadmins:
# * Registration: everyone Super_MumbleUser{,Link}FormTestCase
# * Administration: yes Super_MumbleFormTestCase
# * User texture: everyone
# * User list: yes
# * Log messages: yes
# * Instance scope: ALL
import json
from django.conf import settings
from django.test import TestCase
from django.test.client import Client
from django.contrib.auth.models import User
from models import Mumble, MumbleUser
from utils import ObjectInfo
class ExtDirectFormTestMixin(object):
""" Methods for testing a Form exported via Ext.Direct.
These only define the methods, you will need to inherit your TestCase
from this class and set the following class attributes:
api_baseurl:
The URL under which the Ext.Direct provider has been registered.
formname:
The name of the exported form class.
"""
def setUp(self):
self.cl = Client()
super(ExtDirectFormTestMixin, self).setUp()
self.tid = 1
def testFormApi(self):
rawr = self.cl.get( "%s/%s.js" % ( self.api_baseurl, self.formname.lower() ) )
self.assertEquals( rawr.status_code, 200 )
def formGet( self, data=[] ):
rawr = self.cl.post( self.api_baseurl+'/router',
data=json.dumps({
'tid': self.tid,
'action': ('XD_%s' % self.formname),
'method': 'get',
'data': data,
'type': 'rpc'
}),
content_type='application/json' )
self.tid += 1
response = json.loads(rawr.content)
if response['type'] == "exception":
raise Exception( response["message"] )
self.assert_( "result" in response )
return response['result']
def formPost( self, data={} ):
postdata={
'extAction': ('XD_%s' % self.formname),
'extMethod': 'update',
'extTID': self.tid,
'extType': 'rpc',
'extUpload': 'false',
}
self.tid += 1
postdata.update( data )
rawr = self.cl.post( self.api_baseurl+'/router', data=postdata )
response = json.loads(rawr.content)
if response['type'] == "exception":
raise Exception( response["message"] )
self.assert_( "result" in response )
return response['result']
def generateTestCase( name, formname, data, login=None ):
attrs = {
'fixtures': ['testdb.json'],
'formname': formname,
'api_baseurl': '/mumble/forms',
}
if login:
def setUp( self ):
ExtDirectFormTestMixin.setUp( self )
if not self.cl.login( **login ):
raise Exception( "Login failed" )
attrs['setUp'] = setUp
def mkGet( data, result ):
def testFormGet( self ):
callresult = self.formGet( [{ 'pk': data['pk'] }] )
if "data" in callresult:
del callresult['data'] # don't care
self.assertEquals( callresult, result )
return testFormGet
def mkPost( data, result ):
def testFormPost( self ):
callresult = self.formPost( data )
self.assertEquals( callresult, result,
("errors" in callresult and callresult['errors'] or None)
)
return testFormPost
for testname in data:
if len(data[testname]) == 3:
testdata, getresult, postresult = data[testname]
else:
testdata, getresult = data[testname]
postresult = getresult
attrs.update({
('testForm%sGet' % testname): mkGet( testdata, getresult ),
('testForm%sPost' % testname): mkPost( testdata, postresult ),
})
return type( name, (ExtDirectFormTestMixin, TestCase), attrs )
RES_SUCCESS = {'success': True}
RES_ACCESSDENIED = {'success': False, 'errors': {'__all__': 'access denied'}}
RES_PREVALFAIL = {'success': False, 'errors': {'__all__': 'pre-validation failed'}}
LOGIN_SUPERADMIN = {'username': 'svedrin', 'password': 'passwort'}
LOGIN_UNREGUSER = {'username': 'unreg', 'password': 'passwort'}
LOGIN_USER = {'username': 'user', 'password': 'passwort'}
LOGIN_ADMIN = {'username': 'admin', 'password': 'passwort'}
#############################################################
### ANON: Unauthed (not logged in) users ###
#############################################################
Anon_Registration = generateTestCase(
name = "Anon_Registration",
formname = "MumbleUserForm",
data = {
'My': ( {'pk': 1, 'name': "svedrin", 'password': 'passwort', 'serverid': 1}, RES_ACCESSDENIED ),
'Other': ( {'pk': 1, 'name': "svedrin", 'password': 'passwort'}, RES_ACCESSDENIED )
}
)
Anon_Administration = generateTestCase(
name = "Anon_Administration",
formname = "MumbleForm",
data = { 'My': ( {'pk': 1, 'url': '', 'player': ''}, RES_ACCESSDENIED ) },
)
Anon_UserLink = generateTestCase(
name = "Anon_UserLink",
formname = "MumbleUserLinkForm",
data = {
'My': ( {'pk': 1, 'name': "ohai", 'password': 'failfail', 'serverid': 1}, RES_ACCESSDENIED ),
}
)
#############################################################
### UNREG: Authenticated but no MumbleUser avail ###
#############################################################
Unreg_Registration = generateTestCase(
name = "Unreg_Registration",
formname = "MumbleUserForm",
data = {
'My': ( {'pk': -1, 'name': "neueruser", 'password': 'passwort', 'serverid': 1}, RES_SUCCESS ),
'Taken': ( {'pk': -1, 'name': "svedrin", 'password': 'passwort', 'serverid': 1}, RES_SUCCESS,
{'success': False, 'errors': {'name': 'Another player already registered that name.'}} ),
'Other': ( {'pk': 1, 'name': "svedrin", 'password': 'passwort'}, RES_ACCESSDENIED )
},
login = LOGIN_UNREGUSER
)
if settings.ALLOW_ACCOUNT_LINKING and settings.ALLOW_ACCOUNT_LINKING_ADMINS:
unreg_adminlinkresult = RES_SUCCESS
else:
unreg_adminlinkresult = {'success': False, 'errors': {'__all__': 'Linking Admin accounts is not allowed.'}}
Unreg_UserLink = generateTestCase(
name = "User_UserLink",
formname = "MumbleUserLinkForm",
data = {
'My': ( {'pk': -1, 'name': "nichtadmin", 'password': 'nichtadmin', 'serverid': 1, 'linkacc': 'on'},
RES_ACCESSDENIED, RES_SUCCESS if settings.ALLOW_ACCOUNT_LINKING else RES_ACCESSDENIED ),
'Admin': ( {'pk': -1, 'name': "dochadmin", 'password': 'dochadmin', 'serverid': 1, 'linkacc': 'on'},
RES_ACCESSDENIED, unreg_adminlinkresult ),
'Other': ( {'pk': 1, 'name': "svedrin", 'password': 'passwort', 'serverid': 1}, RES_ACCESSDENIED ),
'Taken': ( {'pk': -1, 'name': "svedrin", 'password': 'passwort', 'serverid': 1}, RES_ACCESSDENIED,
{'success': False, 'errors':{'name': 'Another player already registered that name.'}} ),
},
login = LOGIN_UNREGUSER
)
Unreg_Administration = generateTestCase(
name = "Unreg_Administration",
formname = "MumbleForm",
data = {
'My': ( {'pk': 1, 'name': 'test server', 'url': '', 'player': ''}, RES_ACCESSDENIED ),
'Other': ( {'pk': 2, 'name': 'alealejandro', 'url': '', 'player': ''}, RES_ACCESSDENIED ),
},
login = LOGIN_UNREGUSER,
)
#############################################################
### USER: MumbleUser but not a server admin ###
#############################################################
User_Administration = generateTestCase(
name = "User_Administration",
formname = "MumbleForm",
data = {
'My': ( {'pk': 1, 'name': 'test server', 'url': '', 'player': ''}, RES_ACCESSDENIED ),
'Other': ( {'pk': 2, 'name': 'alealejandro', 'url': '', 'player': ''}, RES_ACCESSDENIED ),
},
login = LOGIN_USER,
)
#############################################################
### ADMIN: MumbleUser is a server admin ###
#############################################################
Admin_Administration = generateTestCase(
name = "Admin_Administration",
formname = "MumbleForm",
data = {
'My': ( {'pk': 1, 'name': 'test server', 'url': '', 'player': ''}, RES_SUCCESS ),
'Other': ( {'pk': 2, 'name': 'alealejandro', 'url': '', 'player': ''}, RES_ACCESSDENIED ),
},
login = LOGIN_ADMIN,
)
#############################################################
### SUPER: User is superadmin, MumbleUser irrelevant ###
#############################################################
Super_Registration = generateTestCase(
name = "Super_Registration",
formname = "MumbleUserForm",
data = {
'My': ( {'pk': 1, 'name': "svedrin", 'password': 'passwort', 'serverid': 1}, RES_SUCCESS ),
'Fail': ( {'pk': 1, 'name': "svedrin", 'password': 'passwort'}, RES_SUCCESS, RES_PREVALFAIL ),
},
login = LOGIN_SUPERADMIN
)
Super_Administration = generateTestCase(
name = "Super_Administration",
formname = "MumbleForm",
data = {
'My': ( {'pk': 1, 'name': 'test server', 'url': '', 'player': ''}, RES_SUCCESS ),
'Other': ( {'pk': 2, 'name': 'alealejandro', 'url': '', 'player': ''}, RES_SUCCESS ),
},
login = LOGIN_SUPERADMIN,
)
Super_UserLink = generateTestCase(
name = "Super_UserLink",
formname = "MumbleUserLinkForm",
data = {
'My': ( {'pk': 1, 'name': "svedrin", 'password': 'passwort', 'serverid': 1},
RES_ACCESSDENIED ),
'Link': ( {'pk': 1, 'name': "svedrin", 'password': 'passwort', 'serverid': 1, 'linkacc': 'on'},
RES_ACCESSDENIED )
},
)
class ExportedForms(TestCase):
""" Makes sure needed forms are exported, and admin forms are not. """
def setUp(self):
self.cl = Client()
def testMumbleUserFormApi(self):
rawr = self.cl.get( '/mumble/forms/mumbleuserform.js' )
self.assertEquals( rawr.status_code, 200 )
def testMumbleUserPasswordFormApi(self):
rawr = self.cl.get( '/mumble/forms/mumbleuserpasswordform.js' )
self.assertEquals( rawr.status_code, 200 )
def testMumbleUserLinkFormApi(self):
rawr = self.cl.get( '/mumble/forms/mumbleuserlinkform.js' )
self.assertEquals( rawr.status_code, 200 )
def testMumbleAdminFormApi(self):
# This form is NOT exported (and shouldn't be) because it's only used in the admin
rawr = self.cl.get( '/mumble/forms/mumbleadminform.js' )
self.assertEquals( rawr.status_code, 404 )
def testMumbleUserAdminFormApi(self):
# This form is NOT exported (and shouldn't be) because it's only used in the admin
rawr = self.cl.get( '/mumble/forms/mumbleuseradminform.js' )
self.assertEquals( rawr.status_code, 404 )
|