Пример #1
0
    def test_one_expired(self, mock_load):
        mock_load.return_value = [
            FakeIPACertificate(
                None,
                subject=self.sub_ca,
                not_after=datetime.now(timezone.utc) + timedelta(days=-3)
            ),
            FakeIPACertificate(
                None,
                subject=self.root_ca,
                not_after=datetime.now(timezone.utc) + timedelta(days=20)
            )
        ]
        framework = object()
        registry.initialize(framework)
        f = IPACAChainExpirationCheck(registry)

        f.config = config.Config()
        f.config.cert_expiration_days = 7
        self.results = capture_results(f)

        assert len(self.results) == 2

        result = self.results.results[0]
        assert result.result == constants.CRITICAL
        assert result.source == 'ipahealthcheck.ipa.certs'
        assert result.check == 'IPACAChainExpirationCheck'
        assert result.kw.get('key') == self.sub_ca
        assert 'expired' in result.kw.get('msg')

        result = self.results.results[1]
        assert result.result == constants.SUCCESS
        assert result.source == 'ipahealthcheck.ipa.certs'
        assert result.check == 'IPACAChainExpirationCheck'
        assert result.kw.get('key') == self.root_ca
Пример #2
0
    def test_expiring_soon(self, mock_load):
        mock_load.return_value = [
            FakeIPACertificate(None,
                               subject=self.sub_ca,
                               not_after=datetime.now(timezone.utc) +
                               timedelta(days=3, minutes=1)),
            FakeIPACertificate(None,
                               subject=self.root_ca,
                               not_after=datetime.now(timezone.utc) +
                               timedelta(days=3, minutes=1))
        ]
        framework = object()
        registry.initialize(framework, config.Config)
        f = IPACAChainExpirationCheck(registry)

        f.config.cert_expiration_days = '7'
        self.results = capture_results(f)

        assert len(self.results) == 2

        result = self.results.results[0]
        assert result.result == constants.WARNING
        assert result.source == 'ipahealthcheck.ipa.certs'
        assert result.check == 'IPACAChainExpirationCheck'
        assert result.kw.get('key') == self.sub_ca
        assert result.kw.get('days') == 3
        assert 'expiring' in result.kw.get('msg')

        result = self.results.results[1]
        assert result.result == constants.WARNING
        assert result.source == 'ipahealthcheck.ipa.certs'
        assert result.check == 'IPACAChainExpirationCheck'
        assert result.kw.get('key') == self.root_ca
        assert result.kw.get('days') == 3
        assert 'expiring' in result.kw.get('msg')