summaryrefslogtreecommitdiff
path: root/tests/auth.wsgi
blob: 77b6eae871769fc386c1da63800c0f22639ddec4 (plain)
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
def allow_access(environ, host):
    print('HOST', host, environ['REQUEST_URI'])
    return True

def check_password(environ, user, password):
    print('USER', user, environ['REQUEST_URI'])
    if user == 'spy':
        if password == 'secret':
            return True
        return False
    elif user == 'witness':
        if password == 'secret':
            return 'protected'
        return False
    return None

import hashlib

def get_realm_hash(environ, user, realm):
    print('USER', user, environ['REQUEST_URI'])
    if user == 'spy':
        value = hashlib.md5()
        # user:realm:password
        input = '%s:%s:%s' % (user, realm, 'secret')
        if not isinstance(input, bytes):
            input = input.encode('UTF-8')
        value.update(input)
        hash = value.hexdigest()
        return hash
    return None

def groups_for_user(environ, user):
    print('GROUP', user, environ['REQUEST_URI'])
    if user == 'spy':
        return ['secret-agents']
    return ['']