summaryrefslogtreecommitdiff
path: root/tests/auth.wsgi
blob: 6d9d668134736df7b361b5aa58f71d9d89340102 (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
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 ['']