forked from apple/ccs-calendarserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://svn.calendarserver.org/repository/calendarserver/CalendarServer/branches/release/CalendarServer-5.3-dev@14169 e27351fd-9f3e-4f54-a53b-843176b1656c
- Loading branch information
1 parent
961bee3
commit 220304c
Showing
9 changed files
with
606 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
## | ||
# Copyright (c) 2005-2014 Apple Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
## | ||
|
||
import twistedcaldav.test.util | ||
from twistedcaldav.util import userAgentProductTokens, matchClientFixes | ||
from twistedcaldav.stdconfig import _updateClientFixes | ||
from twistedcaldav.config import ConfigDict | ||
|
||
class TestUtil(twistedcaldav.test.util.TestCase): | ||
""" | ||
Tests for L{twistedcaldav.util} | ||
""" | ||
def test_userAgentProductTokens(self): | ||
""" | ||
Test that L{userAgentProductTokens} correctly parses a User-Agent header. | ||
""" | ||
for hdr, result in ( | ||
# Valid syntax | ||
("Client/1.0", ["Client/1.0", ]), | ||
("Client/1.0 FooBar/2", ["Client/1.0", "FooBar/2", ]), | ||
("Client/1.0 (commentary here)", ["Client/1.0", ]), | ||
("Client/1.0 (FooBar/2)", ["Client/1.0", ]), | ||
("Client/1.0 (commentary here) FooBar/2", ["Client/1.0", "FooBar/2", ]), | ||
("Client/1.0 (commentary here) FooBar/2 (more commentary here) ", ["Client/1.0", "FooBar/2", ]), | ||
|
||
# Invalid syntax | ||
("Client/1.0 (commentary here FooBar/2", ["Client/1.0", ]), | ||
("Client/1.0 commentary here) FooBar/2", ["Client/1.0", "commentary", "here)", "FooBar/2", ]), | ||
): | ||
self.assertEqual(userAgentProductTokens(hdr), result, msg="Mismatch: {}".format(hdr)) | ||
|
||
|
||
def test_matchClientFixes(self): | ||
""" | ||
Test that L{matchClientFixes} correctly identifies clients with matching fix tokens. | ||
""" | ||
c = ConfigDict() | ||
c.ClientFixes = { | ||
"fix1": [ | ||
"Client/1\\.0.*", | ||
"Client/1\\.1(\\..*)?", | ||
"Client/2", | ||
], | ||
"fix2": [ | ||
"Other/1\\.0.*", | ||
], | ||
} | ||
_updateClientFixes(c) | ||
_updateClientFixes(c) | ||
|
||
# Valid matches | ||
for ua in ( | ||
"Client/1.0 FooBar/2", | ||
"Client/1.0.1 FooBar/2", | ||
"Client/1.0.1.1 FooBar/2", | ||
"Client/1.1 FooBar/2", | ||
"Client/1.1.1 FooBar/2", | ||
"Client/2 FooBar/2", | ||
): | ||
self.assertEqual( | ||
matchClientFixes(c, ua), | ||
set(("fix1",)), | ||
msg="Did not match {}".format(ua), | ||
) | ||
|
||
# Valid non-matches | ||
for ua in ( | ||
"Client/1 FooBar/2", | ||
"Client/1.10 FooBar/2", | ||
"Client/2.0 FooBar/2", | ||
"Client/2.0.1 FooBar/2", | ||
"Client FooBar/2", | ||
"Client/3 FooBar/2", | ||
"Client/3.0 FooBar/2", | ||
"Client/10 FooBar/2", | ||
"Client/10.0 FooBar/2", | ||
"Client/10.0.1 FooBar/2", | ||
"Client/10.0.1 (Client/1.0) FooBar/2", | ||
"Client/10.0.1 (foo Client/1.0 bar) FooBar/2", | ||
): | ||
self.assertEqual( | ||
matchClientFixes(c, ua), | ||
set(), | ||
msg="Incorrectly matched {}".format(ua), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.