[CalendarServer-changes] [15382] CalendarServer/trunk/calendarserver/tap
source_changes at macosforge.org
source_changes at macosforge.org
Fri Dec 11 14:04:20 PST 2015
Revision: 15382
http://trac.calendarserver.org//changeset/15382
Author: cdaboo at apple.com
Date: 2015-12-11 14:04:20 -0800 (Fri, 11 Dec 2015)
Log Message:
-----------
Make sure nin-ascii error log strings are properly output. Clean-up the APNS cert checking to avoid an unhandled exception.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tap/caldav.py
CalendarServer/trunk/calendarserver/tap/test/test_caldav.py
CalendarServer/trunk/calendarserver/tap/util.py
Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py 2015-12-11 20:11:12 UTC (rev 15381)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py 2015-12-11 22:04:20 UTC (rev 15382)
@@ -257,11 +257,17 @@
)
if self.logRotateOnStart:
errorLogFile.rotate()
+ encoding = "utf-8"
else:
errorLogFile = sys.stdout
+ encoding = sys.stdout.encoding
withTime = not (not config.ErrorLogFile and config.ProcessType in ("Slave", "DPS",))
errorLogObserver = Logger.makeFilteredFileLogObserver(errorLogFile, withTime=withTime)
+ # We need to do this because the current Twisted logger implementation fails to setup the encoding
+ # correctly when a L{twisted.python.logile.LogFile} is passed to a {twisted.logger._file.FileLogObserver}
+ errorLogObserver._observers[0]._encoding = encoding
+
# Registering ILogObserver with the Application object
# gets our observer picked up within AppLogger.start( )
app.setComponent(ILogObserver, errorLogObserver)
Modified: CalendarServer/trunk/calendarserver/tap/test/test_caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/test/test_caldav.py 2015-12-11 20:11:12 UTC (rev 15381)
+++ CalendarServer/trunk/calendarserver/tap/test/test_caldav.py 2015-12-11 22:04:20 UTC (rev 15382)
@@ -40,8 +40,7 @@
from twisted.internet.defer import Deferred, inlineCallbacks, succeed, gatherResults
from twisted.internet.task import Clock
from twisted.internet import reactor
-from twisted.application.service import (IService, IServiceCollection
- )
+from twisted.application.service import IService, IServiceCollection, Application
from twisted.application import internet
from twext.python.log import Logger
@@ -66,11 +65,11 @@
CalDAVOptions, CalDAVServiceMaker, CalDAVService, GroupOwnedUNIXServer,
DelayedStartupProcessMonitor, DelayedStartupLineLogger, TwistdSlaveProcess,
_CONTROL_SERVICE_NAME, getSystemIDs, PreProcessingService,
- DataStoreMonitor
-)
+ DataStoreMonitor, ErrorLoggingMultiService)
from calendarserver.provision.root import RootResource
from StringIO import StringIO
import tempfile
+from twisted.python.log import ILogObserver
log = Logger()
@@ -453,6 +452,36 @@
+class TestErrorLoggingMultiService(TestCase):
+
+ def test_nonAsciiLog(self):
+ """
+ Make sure that the file based error log can write non ascii data
+ """
+
+ logpath = self.mktemp()
+ service = ErrorLoggingMultiService(
+ True,
+ logpath,
+ 10000,
+ 10,
+ False,
+ )
+ app = Application("non-ascii")
+ service.setServiceParent(app)
+
+ observer = app.getComponent(ILogObserver, None)
+ self.assertTrue(observer is not None)
+
+ log = Logger(observer=observer)
+ log.error(u"Couldn\u2019t be wrong")
+
+ with open(logpath) as f:
+ logentry = f.read()
+ self.assertIn("Couldn\xe2\x80\x99t be wrong", logentry)
+
+
+
class TestProcessMonitor(ProcessMonitor):
def startProcess(self, name):
Modified: CalendarServer/trunk/calendarserver/tap/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/util.py 2015-12-11 20:11:12 UTC (rev 15381)
+++ CalendarServer/trunk/calendarserver/tap/util.py 2015-12-11 22:04:20 UTC (rev 15382)
@@ -1378,31 +1378,29 @@
):
protoConfig = config.Notifications.Services.APNS[protocol]
- # Verify the cert exists
if hasattr(OpenSSL, "__SecureTransport__"):
if protoConfig.KeychainIdentity:
- # Verify we can extract the topic
- if not protoConfig.Topic:
- topic = getAPNTopicFromIdentity(protoConfig.KeychainIdentity)
- protoConfig.Topic = topic
- if not protoConfig.Topic:
- postAlert("PushNotificationKeychainIdentityAlert", 0, [])
- message = "Cannot extract APN topic"
- return False, message
-
- # Fall through to see if we can load the identity from the keychain
- certificate_title = "Keychain: {}".format(protoConfig.KeychainIdentity)
-
+ # Verify the identity exists
error = OpenSSL.crypto.check_keychain_identity(protoConfig.KeychainIdentity)
if error:
message = (
"The {proto} APNS Keychain Identity ({cert}) cannot be used: {reason}".format(
proto=protocol,
- cert=certificate_title,
+ cert=protoConfig.KeychainIdentity,
reason=error
)
)
return False, message
+
+ # Verify we can extract the topic
+ if not protoConfig.Topic:
+ topic = getAPNTopicFromIdentity(protoConfig.KeychainIdentity)
+ protoConfig.Topic = topic
+ if not protoConfig.Topic:
+ postAlert("PushNotificationKeychainIdentityAlert", 0, [])
+ message = "Cannot extract APN topic"
+ return False, message
+
else:
message = (
"No {proto} APNS Keychain Identity was set".format(
@@ -1413,6 +1411,7 @@
return False, message
else:
+ # Verify the cert exists
if not os.path.exists(protoConfig.CertificatePath):
message = (
"The {proto} APNS certificate ({cert}) is missing".format(
@@ -1466,7 +1465,7 @@
message = (
"The {proto} APNS Keychain Identity ({cert}) cannot be used: {reason}".format(
proto=protocol,
- cert=certificate_title,
+ cert=protoConfig.KeychainIdentity,
reason=str(e)
)
)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20151211/b1a6d040/attachment-0001.html>
More information about the calendarserver-changes
mailing list