Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 82 lines (64 sloc) 2.597 kb
e3d7a32 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2142 5dc97367-97f1...
alobbs authored
1 from conf import *
2 from base import *
3
4 MAGIC = "Cherokee supports htdigest files"
5 REALM = "realm"
6 USER = "username"
7 PASSWD = "itissecret"
8 DIR = "digest_htdigest2"
9
10 ACCOUNTS=(
11 ('joseph','joseph'),
12 ('username','itissecret'),
13 )
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
14
e3d7a32 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2142 5dc97367-97f1...
alobbs authored
15 CONF = """
6acf83d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2184 5dc97367-97f1...
alobbs authored
16 vserver!1!rule!1750!match = directory
17 vserver!1!rule!1750!match!directory = %s
18 vserver!1!rule!1750!match!final = 0
19 vserver!1!rule!1750!auth = htdigest
20 vserver!1!rule!1750!auth!methods = digest
21 vserver!1!rule!1750!auth!realm = %s
22 vserver!1!rule!1750!auth!passwdfile = %s
e3d7a32 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2142 5dc97367-97f1...
alobbs authored
23 """
24
25 class Test (TestBase):
26 def __init__ (self):
bc8d926 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2179 5dc97367-97f1...
alobbs authored
27 TestBase.__init__ (self, __file__)
e3d7a32 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2142 5dc97367-97f1...
alobbs authored
28 self.name = "Digest - htdigest: Valid user/passwd 2"
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
29
e3d7a32 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2142 5dc97367-97f1...
alobbs authored
30 self.expected_error = 200
31 self.expected_content = MAGIC
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
32
e3d7a32 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2142 5dc97367-97f1...
alobbs authored
33 def JustBefore (self, www):
34 import random
35 USER, PASSWD = random.choice(ACCOUNTS)
36
37 # It will read a validad nonce value just before each test
38 #
bc8d926 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2179 5dc97367-97f1...
alobbs authored
39 nested = TestBase(__file__)
e3d7a32 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2142 5dc97367-97f1...
alobbs authored
40 nested.request = "GET /%s/file HTTP/1.0\r\n" % (DIR)
b368e2d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2444 5dc97367-97f1...
alobbs authored
41 nested.Run(HOST, PORT, 0)
e3d7a32 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2142 5dc97367-97f1...
alobbs authored
42
43 # Parse the authentication information line
44 #
45 nested.digest = self.Digest()
46 vals = nested.digest.ParseHeader (nested.reply)
47
48 # Calculate the response value
49 #
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
50 response = nested.digest.CalculateResponse (USER, REALM, PASSWD, "GET", "/%s/file" % (DIR),
e3d7a32 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2142 5dc97367-97f1...
alobbs authored
51 vals["nonce"], vals["qop"], vals["cnonce"], vals["nc"])
52
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
53 # At this point, we got a valid nonce, so let's write the
e3d7a32 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2142 5dc97367-97f1...
alobbs authored
54 # request..
55 self.request = "GET /%s/file HTTP/1.0\r\n" % (DIR) +\
56 "Authorization: Digest response=\"%s\", username=\"%s\", realm=\"%s\", uri=\"%s\", nonce=\"%s\", qop=\"%s\", algorithm=\"%s\"\r\n" % \
57 (response, USER, REALM, "/%s/file" %(DIR), vals["nonce"], vals["qop"], vals["algorithm"])
58
59
60 def Prepare (self, www):
6e1a928 @alobbs Fixes the QA bench so it can run on Python 2.4
alobbs authored
61 try:
62 from hashlib import md5
63 except ImportError:
64 from md5 import md5
e3d7a32 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2142 5dc97367-97f1...
alobbs authored
65
66 # Create the infrastructure
67 #
68 test_dir = self.Mkdir (www, DIR)
69 self.WriteFile (test_dir, "file", 0444, MAGIC)
70
71 # Prepare the password file
72 #
73 kd = lambda x: md5(':'.join(x)).hexdigest()
74 authlines = (':'.join( (user,REALM,kd((user,REALM,password))) ) for user,password in ACCOUNTS)
75
76
77 passfile = self.WriteFile (test_dir, ".passwd", 0444, '\n'.join(authlines))
78
79 # Set the configuration
80 #
81 self.conf = CONF % ('/%s'%(DIR), REALM, passfile)
Something went wrong with that request. Please try again.