Exemplo n.º 1
0
    def makeService(self, options):
        """
        Return a service
        """
        try:
            from setproctitle import setproctitle
        except ImportError:
            pass
        else:
            setproctitle("CalendarServer Directory Proxy Service")

        try:
            directory = directoryFromConfig(config)
        except Exception as e:
            log.error("Failed to create directory service", error=e)
            raise

        log.info("Created directory service")

        return strPortsService(
            "unix:{path}:mode=660".format(
                path=config.DirectoryProxy.SocketPath
            ),
            DirectoryProxyAMPFactory(directory)
        )
Exemplo n.º 2
0
    def setUp(self):

        self.serverRoot = self.mktemp()
        os.mkdir(self.serverRoot)
        self.absoluteServerRoot = os.path.abspath(self.serverRoot)

        configRoot = os.path.join(self.absoluteServerRoot, "Config")
        if not os.path.exists(configRoot):
            os.makedirs(configRoot)

        dataRoot = os.path.join(self.absoluteServerRoot, "Data")
        if not os.path.exists(dataRoot):
            os.makedirs(dataRoot)

        documentRoot = os.path.join(self.absoluteServerRoot, "Documents")
        if not os.path.exists(documentRoot):
            os.makedirs(documentRoot)

        logRoot = os.path.join(self.absoluteServerRoot, "Logs")
        if not os.path.exists(logRoot):
            os.makedirs(logRoot)

        runRoot = os.path.join(self.absoluteServerRoot, "Run")
        if not os.path.exists(runRoot):
            os.makedirs(runRoot)

        config.reset()

        testRoot = os.path.join(os.path.dirname(__file__), "gateway")
        templateName = os.path.join(testRoot, "caldavd.plist")
        with open(templateName) as templateFile:
            template = templateFile.read()

        databaseRoot = os.path.abspath("_spawned_scripts_db" + str(os.getpid()))
        newConfig = template % {
            "ServerRoot": self.absoluteServerRoot,
            "DataRoot": dataRoot,
            "DatabaseRoot": databaseRoot,
            "DocumentRoot": documentRoot,
            "ConfigRoot": configRoot,
            "LogRoot": logRoot,
            "RunRoot": runRoot,
            "WritablePlist": os.path.join(
                os.path.abspath(configRoot), "caldavd-writable.plist"
            ),
        }
        configFilePath = FilePath(
            os.path.join(configRoot, "caldavd.plist")
        )

        configFilePath.setContent(newConfig)

        self.configFileName = configFilePath.path
        config.load(self.configFileName)

        config.Memcached.Pools.Default.ClientEnabled = False
        config.Memcached.Pools.Default.ServerEnabled = False
        ClientFactory.allowTestCache = True
        memcacher.Memcacher.allowTestCache = True
        memcacher.Memcacher.reset()
        config.DirectoryAddressBook.Enabled = False
        config.UsePackageTimezones = True

        origUsersFile = FilePath(
            os.path.join(
                os.path.dirname(__file__),
                "gateway",
                "users-groups.xml"
            )
        )
        copyUsersFile = FilePath(
            os.path.join(config.DataRoot, "accounts.xml")
        )
        origUsersFile.copyTo(copyUsersFile)

        origResourcesFile = FilePath(
            os.path.join(
                os.path.dirname(__file__),
                "gateway",
                "resources-locations.xml"
            )
        )
        copyResourcesFile = FilePath(
            os.path.join(config.DataRoot, "resources.xml")
        )
        origResourcesFile.copyTo(copyResourcesFile)

        origAugmentFile = FilePath(
            os.path.join(
                os.path.dirname(__file__),
                "gateway",
                "augments.xml"
            )
        )
        copyAugmentFile = FilePath(os.path.join(config.DataRoot, "augments.xml"))
        origAugmentFile.copyTo(copyAugmentFile)

        self.notifierFactory = StubNotifierFactory()
        self.store = yield theStoreBuilder.buildStore(self, self.notifierFactory)
        self.directory = directoryFromConfig(config, self.store)
Exemplo n.º 3
0
    def test_directoryFromConfig(self):

        config = ConfigDict(
            {
                "DataRoot": self.dataRoot,
                "Authentication": {
                    "Wiki": {
                        "Enabled": True,
                        "EndpointDescriptor": "tcp:host=localhost:port=4444",
                    },
                },
                "DirectoryService": {
                    "Enabled": True,
                    "type": "XML",
                    "params": {
                        "xmlFile": "accounts.xml",
                        "recordTypes": ["users", "groups"],
                    },
                },
                "ResourceService": {
                    "Enabled": True,
                    "type": "XML",
                    "params": {
                        "xmlFile": "resources.xml",
                        "recordTypes": ["locations", "resources", "addresses"],
                    },
                },
                "AugmentService": {
                    "Enabled": True,
                    # FIXME: This still uses an actual class name:
                    "type": "twistedcaldav.directory.augment.AugmentXMLDB",
                    "params": {
                        "xmlFiles": ["augments.xml"],
                    },
                },
                "Servers": {
                    "Enabled": False,
                },
                "DirectoryProxy": {
                    "SocketPath": "directory-proxy.sock",
                    "InProcessCachingSeconds": 60,
                    "InSidecarCachingSeconds": 120,
                },
                "DirectoryFilterStartsWith": False,
            }
        )

        store = StubStore()
        service = directoryFromConfig(config, store)

        # Make sure XML files were created
        dataRoot = FilePath(self.dataRoot)
        self.assertTrue(dataRoot.child("accounts.xml").exists())
        self.assertTrue(dataRoot.child("resources.xml").exists())
        self.assertTrue(dataRoot.child("augments.xml").exists())

        # Inspect the directory service structure
        self.assertTrue(isinstance(service, AugmentedDirectoryService))
        self.assertTrue(isinstance(service._directory, AggregateDirectoryService))
        self.assertEquals(len(service._directory.services), 4)
        self.assertTrue(
            isinstance(service._directory.services[0], DelegateDirectoryService)
        )
        self.assertEquals(
            set(service._directory.services[0].recordTypes()),
            set(
                [
                    DelegateRecordType.readDelegateGroup,
                    DelegateRecordType.writeDelegateGroup,
                    DelegateRecordType.readDelegatorGroup,
                    DelegateRecordType.writeDelegatorGroup,
                ]
            )
        )
        self.assertTrue(
            isinstance(service._directory.services[1], CachingDirectoryService)
        )
        self.assertTrue(
            isinstance(service._directory.services[1]._directory, XMLDirectoryService)
        )
        self.assertEquals(
            set(service._directory.services[1]._directory.recordTypes()),
            set([RecordType.user, RecordType.group])
        )
        self.assertTrue(
            isinstance(service._directory.services[2]._directory, XMLDirectoryService)
        )
        self.assertEquals(
            set(service._directory.services[2]._directory.recordTypes()),
            set(
                [
                    CalRecordType.location,
                    CalRecordType.resource,
                    CalRecordType.address
                ]
            )
        )
        self.assertTrue(
            isinstance(service._directory.services[3], WikiDirectoryService)
        )
        self.assertEquals(
            set(service._directory.services[3].recordTypes()),
            set([WikiRecordType.macOSXServerWiki])
        )

        # And make sure it's functional:
        record = yield service.recordWithUID("group07")
        self.assertEquals(record.fullNames, [u'Group 07'])
Exemplo n.º 4
0
    def test_directoryFromConfig(self):

        config = ConfigDict({
            "DataRoot": self.dataRoot,
            "Authentication": {
                "Wiki": {
                    "Enabled": True,
                    "EndpointDescriptor": "tcp:host=localhost:port=4444",
                },
            },
            "DirectoryService": {
                "Enabled": True,
                "type": "xml",
                "params": {
                    "xmlFile": "accounts.xml",
                    "recordTypes": ["users", "groups"],
                },
            },
            "ResourceService": {
                "Enabled": True,
                "type": "xml",
                "params": {
                    "xmlFile": "resources.xml",
                    "recordTypes": ["locations", "resources", "addresses"],
                },
            },
            "AugmentService": {
                "type": "xml",
                "params": {
                    "xmlFiles": ["augments.xml"],
                },
            },
            "Servers": {
                "Enabled": False,
            },
            "DirectoryProxy": {
                "Enabled": False,
                "SocketPath": "directory-proxy.sock",
                "InSidecarCachingSeconds": 120,
            },
            "DirectoryCaching": {
                "CachingSeconds": 60,
                "NegativeCachingEnabled": True,
                "LookupsBetweenPurges": 0,
            },
            "DirectoryFilterStartsWith": False,
        })

        store = StubStore()
        service = directoryFromConfig(config, store)

        # Make sure XML files were created
        dataRoot = FilePath(self.dataRoot)
        self.assertTrue(dataRoot.child("accounts.xml").exists())
        self.assertTrue(dataRoot.child("resources.xml").exists())
        self.assertTrue(dataRoot.child("augments.xml").exists())

        # Inspect the directory service structure
        self.assertTrue(isinstance(service, AugmentedDirectoryService))
        self.assertTrue(
            isinstance(service._directory, AggregateDirectoryService))
        self.assertEquals(len(service._directory.services), 4)
        self.assertTrue(
            isinstance(service._directory.services[0],
                       DelegateDirectoryService))
        self.assertEquals(
            set(service._directory.services[0].recordTypes()),
            set([
                DelegateRecordType.readDelegateGroup,
                DelegateRecordType.writeDelegateGroup,
                DelegateRecordType.readDelegatorGroup,
                DelegateRecordType.writeDelegatorGroup,
            ]))
        self.assertTrue(
            isinstance(service._directory.services[1],
                       CachingDirectoryService))
        self.assertTrue(
            isinstance(service._directory.services[1]._directory,
                       XMLDirectoryService))
        self.assertEquals(
            set(service._directory.services[1]._directory.recordTypes()),
            set([RecordType.user, RecordType.group]))
        self.assertTrue(
            isinstance(service._directory.services[2]._directory,
                       XMLDirectoryService))
        self.assertEquals(
            set(service._directory.services[2]._directory.recordTypes()),
            set([
                CalRecordType.location, CalRecordType.resource,
                CalRecordType.address
            ]))
        self.assertTrue(
            isinstance(service._directory.services[3], WikiDirectoryService))
        self.assertEquals(set(service._directory.services[3].recordTypes()),
                          set([WikiRecordType.macOSXServerWiki]))

        # And make sure it's functional:
        record = yield service.recordWithUID("group07")
        self.assertEquals(record.fullNames, [u'Group 07'])
Exemplo n.º 5
0
    def setUp(self):

        self.serverRoot = self.mktemp()
        os.mkdir(self.serverRoot)
        self.absoluteServerRoot = os.path.abspath(self.serverRoot)

        configRoot = os.path.join(self.absoluteServerRoot, "Config")
        if not os.path.exists(configRoot):
            os.makedirs(configRoot)

        dataRoot = os.path.join(self.absoluteServerRoot, "Data")
        if not os.path.exists(dataRoot):
            os.makedirs(dataRoot)

        documentRoot = os.path.join(self.absoluteServerRoot, "Documents")
        if not os.path.exists(documentRoot):
            os.makedirs(documentRoot)

        logRoot = os.path.join(self.absoluteServerRoot, "Logs")
        if not os.path.exists(logRoot):
            os.makedirs(logRoot)

        runRoot = os.path.join(self.absoluteServerRoot, "Run")
        if not os.path.exists(runRoot):
            os.makedirs(runRoot)

        config.reset()

        testRoot = os.path.join(os.path.dirname(__file__), "gateway")
        templateName = os.path.join(testRoot, "caldavd.plist")
        templateFile = open(templateName)
        template = templateFile.read()
        templateFile.close()

        databaseRoot = os.path.abspath("_spawned_scripts_db" + str(os.getpid()))
        newConfig = template % {
            "ServerRoot": self.absoluteServerRoot,
            "DataRoot": dataRoot,
            "DatabaseRoot": databaseRoot,
            "DocumentRoot": documentRoot,
            "ConfigRoot": configRoot,
            "LogRoot": logRoot,
            "RunRoot": runRoot,
            "WritablePlist": os.path.join(
                os.path.abspath(configRoot), "caldavd-writable.plist"
            ),
        }
        configFilePath = FilePath(
            os.path.join(configRoot, "caldavd.plist")
        )

        configFilePath.setContent(newConfig)

        self.configFileName = configFilePath.path
        config.load(self.configFileName)

        config.Memcached.Pools.Default.ClientEnabled = False
        config.Memcached.Pools.Default.ServerEnabled = False
        ClientFactory.allowTestCache = True
        memcacher.Memcacher.allowTestCache = True
        memcacher.Memcacher.reset()
        config.DirectoryAddressBook.Enabled = False
        config.UsePackageTimezones = True

        origUsersFile = FilePath(
            os.path.join(
                os.path.dirname(__file__),
                "gateway",
                "users-groups.xml"
            )
        )
        copyUsersFile = FilePath(
            os.path.join(config.DataRoot, "accounts.xml")
        )
        origUsersFile.copyTo(copyUsersFile)

        origResourcesFile = FilePath(
            os.path.join(
                os.path.dirname(__file__),
                "gateway",
                "resources-locations.xml"
            )
        )
        copyResourcesFile = FilePath(
            os.path.join(config.DataRoot, "resources.xml")
        )
        origResourcesFile.copyTo(copyResourcesFile)

        origAugmentFile = FilePath(
            os.path.join(
                os.path.dirname(__file__),
                "gateway",
                "augments.xml"
            )
        )
        copyAugmentFile = FilePath(os.path.join(config.DataRoot, "augments.xml"))
        origAugmentFile.copyTo(copyAugmentFile)

        self.notifierFactory = StubNotifierFactory()
        self.store = yield theStoreBuilder.buildStore(self, self.notifierFactory)
        self.directory = directoryFromConfig(config, self.store)
Exemplo n.º 6
0
    def test_directoryFromConfig(self):

        config = ConfigDict({
            "DataRoot": self.dataRoot,
            "Authentication": {
                "Wiki": {
                    "Enabled": True,
                    "CollabHost": "localhost",
                    "CollabPort": 4444,
                },
            },
            "DirectoryService": {
                "Enabled": True,
                "type": "XML",
                "params": {
                    "xmlFile": "accounts.xml",
                    "recordTypes": ["users", "groups"],
                },
            },
            "ResourceService": {
                "Enabled": True,
                "type": "XML",
                "params": {
                    "xmlFile": "resources.xml",
                    "recordTypes": ["locations", "resources", "addresses"],
                },
            },
            "AugmentService": {
                "Enabled": True,
                # FIXME: This still uses an actual class name:
                "type": "twistedcaldav.directory.augment.AugmentXMLDB",
                "params": {
                    "xmlFiles": ["augments.xml"],
                },
            },
        })

        store = StubStore()
        service = directoryFromConfig(config, store=store)

        # Make sure XML files were created
        dataRoot = FilePath(self.dataRoot)
        self.assertTrue(dataRoot.child("accounts.xml").exists())
        self.assertTrue(dataRoot.child("resources.xml").exists())
        self.assertTrue(dataRoot.child("augments.xml").exists())

        # Inspect the directory service structure
        self.assertTrue(isinstance(service, AugmentedDirectoryService))
        self.assertTrue(
            isinstance(service._directory, AggregateDirectoryService))
        self.assertEquals(len(service._directory.services), 4)
        self.assertTrue(
            isinstance(service._directory.services[0], XMLDirectoryService))
        self.assertEquals(set(service._directory.services[0].recordTypes()),
                          set([RecordType.user, RecordType.group]))
        self.assertTrue(
            isinstance(service._directory.services[1], XMLDirectoryService))
        self.assertEquals(
            set(service._directory.services[1].recordTypes()),
            set([
                CalRecordType.location, CalRecordType.resource,
                CalRecordType.address
            ]))
        self.assertTrue(
            isinstance(service._directory.services[2],
                       DelegateDirectoryService))
        self.assertEquals(
            set(service._directory.services[2].recordTypes()),
            set([
                DelegateRecordType.readDelegateGroup,
                DelegateRecordType.writeDelegateGroup,
                DelegateRecordType.readDelegatorGroup,
                DelegateRecordType.writeDelegatorGroup,
            ]))
        self.assertTrue(
            isinstance(service._directory.services[3], WikiDirectoryService))
        self.assertEquals(set(service._directory.services[3].recordTypes()),
                          set([WikiRecordType.macOSXServerWiki]))

        # And make sure it's functional:
        record = yield service.recordWithUID("group07")
        self.assertEquals(record.fullNames, [u'Group 07'])