<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12613] CalendarServer/trunk/txdav/dps</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12613">12613</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-02-07 15:48:49 -0800 (Fri, 07 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Test for DPS digest auth</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavdpsclientpy">CalendarServer/trunk/txdav/dps/client.py</a></li>
<li><a href="#CalendarServertrunktxdavdpscommandspy">CalendarServer/trunk/txdav/dps/commands.py</a></li>
<li><a href="#CalendarServertrunktxdavdpsserverpy">CalendarServer/trunk/txdav/dps/server.py</a></li>
<li><a href="#CalendarServertrunktxdavdpstesttest_clientpy">CalendarServer/trunk/txdav/dps/test/test_client.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktxdavdpsclientpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/dps/client.py (12612 => 12613)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/client.py        2014-02-07 20:43:59 UTC (rev 12612)
+++ CalendarServer/trunk/txdav/dps/client.py        2014-02-07 23:48:49 UTC (rev 12613)
</span><span class="lines">@@ -186,6 +186,7 @@
</span><span class="cx">         return self.service._call(
</span><span class="cx">             VerifyHTTPDigestCommand,
</span><span class="cx">             lambda x: x['authenticated'],
</span><ins>+            uid=self.uid.encode(&quot;utf-8&quot;),
</ins><span class="cx">             username=username.encode(&quot;utf-8&quot;),
</span><span class="cx">             realm=realm.encode(&quot;utf-8&quot;),
</span><span class="cx">             uri=uri.encode(&quot;utf-8&quot;),
</span><span class="lines">@@ -212,7 +213,7 @@
</span><span class="cx">     print(&quot;uid: {r}&quot;.format(r=record))
</span><span class="cx">     if record:
</span><span class="cx">         authenticated = (yield record.verifyPlaintextPassword(&quot;erd&quot;))
</span><del>-        print(&quot;authenticated: {a}&quot;.format(a=authenticated))
</del><ins>+        print(&quot;plain auth: {a}&quot;.format(a=authenticated))
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     record = (yield ds.recordWithGUID(&quot;A3B1158F-0564-4F5B-81E4-A89EA5FF81B0&quot;))
</span><span class="cx">     print(&quot;guid: {r}&quot;.format(r=record))
</span></span></pre></div>
<a id="CalendarServertrunktxdavdpscommandspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/dps/commands.py (12612 => 12613)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/commands.py        2014-02-07 20:43:59 UTC (rev 12612)
+++ CalendarServer/trunk/txdav/dps/commands.py        2014-02-07 23:48:49 UTC (rev 12613)
</span><span class="lines">@@ -94,6 +94,7 @@
</span><span class="cx"> 
</span><span class="cx"> class VerifyHTTPDigestCommand(amp.Command):
</span><span class="cx">     arguments = [
</span><ins>+        ('uid', amp.String()),
</ins><span class="cx">         ('username', amp.String()),
</span><span class="cx">         ('realm', amp.String()),
</span><span class="cx">         ('uri', amp.String()),
</span></span></pre></div>
<a id="CalendarServertrunktxdavdpsserverpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/dps/server.py (12612 => 12613)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/server.py        2014-02-07 20:43:59 UTC (rev 12612)
+++ CalendarServer/trunk/txdav/dps/server.py        2014-02-07 23:48:49 UTC (rev 12613)
</span><span class="lines">@@ -175,9 +175,10 @@
</span><span class="cx">     @VerifyHTTPDigestCommand.responder
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def verifyHTTPDigest(
</span><del>-        self, username, realm, uri, nonce, cnonce,
</del><ins>+        self, uid, username, realm, uri, nonce, cnonce,
</ins><span class="cx">         algorithm, nc, qop, response, method,
</span><span class="cx">     ):
</span><ins>+        uid = uid.decode(&quot;utf-8&quot;)
</ins><span class="cx">         username = username.decode(&quot;utf-8&quot;)
</span><span class="cx">         realm = realm.decode(&quot;utf-8&quot;)
</span><span class="cx">         uri = uri.decode(&quot;utf-8&quot;)
</span><span class="lines">@@ -189,8 +190,7 @@
</span><span class="cx">         response = response.decode(&quot;utf-8&quot;)
</span><span class="cx">         method = method.decode(&quot;utf-8&quot;)
</span><span class="cx">         log.debug(&quot;VerifyHTTPDigest: {u}&quot;, u=username)
</span><del>-        record = (yield self._directory.recordWithShortName(
-            self._directory.recordType.user, username))
</del><ins>+        record = (yield self._directory.recordWithUID(uid))
</ins><span class="cx">         authenticated = False
</span><span class="cx">         if record is not None:
</span><span class="cx">             authenticated = (
</span></span></pre></div>
<a id="CalendarServertrunktxdavdpstesttest_clientpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/dps/test/test_client.py (12612 => 12613)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/test/test_client.py        2014-02-07 20:43:59 UTC (rev 12612)
+++ CalendarServer/trunk/txdav/dps/test/test_client.py        2014-02-07 23:48:49 UTC (rev 12613)
</span><span class="lines">@@ -25,9 +25,17 @@
</span><span class="cx"> from twisted.trial import unittest
</span><span class="cx"> from txdav.dps.client import DirectoryService
</span><span class="cx"> from txdav.dps.server import DirectoryProxyAMPProtocol
</span><del>-from txdav.who.xml import DirectoryService as XMLDirectoryService
</del><span class="cx"> 
</span><span class="cx"> 
</span><ins>+testMode = &quot;xml&quot;  # &quot;xml&quot; or &quot;od&quot;
+if testMode == &quot;xml&quot;:
+    from txdav.who.xml import DirectoryService as XMLDirectoryService
+elif testMode == &quot;od&quot;:
+    odpw = &quot;__secret__&quot;
+    from twext.who.opendirectory import DirectoryService as OpenDirectoryService
+
+
+
</ins><span class="cx"> class DPSClientTest(unittest.TestCase):
</span><span class="cx"> 
</span><span class="cx">     def setUp(self):
</span><span class="lines">@@ -36,8 +44,11 @@
</span><span class="cx">         self.directory = DirectoryService(None)
</span><span class="cx"> 
</span><span class="cx">         # The &quot;remote&quot; directory service
</span><del>-        path = os.path.join(os.path.dirname(__file__), &quot;test.xml&quot;)
-        remoteDirectory = XMLDirectoryService(FilePath(path))
</del><ins>+        if testMode == &quot;xml&quot;:
+            path = os.path.join(os.path.dirname(__file__), &quot;test.xml&quot;)
+            remoteDirectory = XMLDirectoryService(FilePath(path))
+        elif testMode == &quot;od&quot;:
+            remoteDirectory = OpenDirectoryService()
</ins><span class="cx"> 
</span><span class="cx">         # Connect the two services directly via an IOPump
</span><span class="cx">         client = AMP()
</span><span class="lines">@@ -102,57 +113,61 @@
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def test_verifyPlaintextPassword(self):
</span><del>-        record = (yield self.directory.recordWithUID(&quot;__dre__&quot;))
</del><ins>+        if testMode == &quot;xml&quot;:
+            expectations = (
+                (&quot;erd&quot;, True),    # Correct
+                (&quot;wrong&quot;, False)  # Incorrect
+            )
+            record = (yield self.directory.recordWithShortName(RecordType.user, &quot;dre&quot;))
+        elif testMode == &quot;od&quot;:
+            expectations = (
+                (odpw, True),     # Correct
+                (&quot;wrong&quot;, False)  # Incorrect
+            )
+            record = (yield self.directory.recordWithGUID(&quot;D0B38B00-4166-11DD-B22C-A07C87F02F6A&quot;))
</ins><span class="cx"> 
</span><del>-        # Correct password
-        authenticated = (yield record.verifyPlaintextPassword(&quot;erd&quot;))
-        self.assertTrue(authenticated)
</del><ins>+        for password, answer in expectations:
+            authenticated = (yield record.verifyPlaintextPassword(password))
+            self.assertEquals(authenticated, answer)
</ins><span class="cx"> 
</span><del>-        # Incorrect password
-        authenticated = (yield record.verifyPlaintextPassword(&quot;wrong&quot;))
-        self.assertFalse(authenticated)
</del><span class="cx"> 
</span><del>-
</del><span class="cx">     @inlineCallbacks
</span><span class="cx">     def test_verifyHTTPDigest(self):
</span><del>-        username = &quot;dre&quot;
-        record = (yield self.directory.recordWithShortName(
-            RecordType.user, username))
-        realm = u&quot;xyzzy&quot;
</del><ins>+        if testMode == &quot;xml&quot;:
+            username = &quot;dre&quot;
+            expectations = (
+                (&quot;erd&quot;, True),    # Correct
+                (&quot;wrong&quot;, False)  # Incorrect
+            )
+            record = (yield self.directory.recordWithShortName(RecordType.user, &quot;dre&quot;))
+        elif testMode == &quot;od&quot;:
+            username = &quot;sagen&quot;
+            expectations = (
+                (odpw, True),     # Correct
+                (&quot;wrong&quot;, False)  # Incorrect
+            )
+            record = (yield self.directory.recordWithGUID(&quot;D0B38B00-4166-11DD-B22C-A07C87F02F6A&quot;))
+
+        realm = &quot;host.example.com&quot;
</ins><span class="cx">         nonce = &quot;128446648710842461101646794502&quot;
</span><del>-        nc = &quot;00000001&quot;
-        cnonce = &quot;/rrD6TqPA3lHRmg+fw/vyU6oWoQgzK7h9yWrsCmv/lE=&quot;
-        algo = &quot;md5&quot;
</del><ins>+        algorithm = &quot;md5&quot;
</ins><span class="cx">         uri = &quot;http://host.example.com&quot;
</span><span class="cx">         method = &quot;GET&quot;
</span><del>-        qop = &quot;&quot;
</del><span class="cx"> 
</span><del>-        # Correct password
-        password = &quot;erd&quot;
-        expected = calcResponse(
-            calcHA1(algo, username, realm, password, nonce, cnonce),
-            calcHA2(algo, method, uri, qop, None),
-            algo, nonce, nc, cnonce, qop)
</del><ins>+        for password, answer in expectations:
+            for qop, nc, cnonce in (
+                (&quot;&quot;, &quot;&quot;, &quot;&quot;),
+                (&quot;auth&quot;, &quot;00000001&quot;, &quot;/rrD6TqPA3lHRmg+fw/vyU6oWoQgzK7h9yWrsCmv/lE=&quot;),
+            ):
+                response = calcResponse(
+                    calcHA1(algorithm, username, realm, password, nonce, cnonce),
+                    calcHA2(algorithm, method, uri, qop, None),
+                    algorithm, nonce, nc, cnonce, qop)
</ins><span class="cx"> 
</span><del>-        authenticated = (
-            yield record.verifyHTTPDigest(
-                username, realm, uri, nonce, cnonce, algo, nc, qop,
-                expected, method
-            )
-        )
-        self.assertTrue(authenticated)
-
-        # Incorrect password
-        password = &quot;wrong&quot;
-        expected = calcResponse(
-            calcHA1(algo, username, realm, password, nonce, cnonce),
-            calcHA2(algo, method, uri, qop, None),
-            algo, nonce, nc, cnonce, qop)
-
-        authenticated = (
-            yield record.verifyHTTPDigest(
-                username, realm, uri, nonce, cnonce, algo, nc, qop,
-                expected, method
-            )
-        )
-        self.assertFalse(authenticated)
</del><ins>+                authenticated = (
+                    yield record.verifyHTTPDigest(
+                        username, realm, uri, nonce, cnonce, algorithm, nc, qop,
+                        response, method
+                    )
+                )
+                self.assertEquals(authenticated, answer)
</ins></span></pre>
</div>
</div>

</body>
</html>