コード例 #1
0
    def test_analyze_string_content(self, payload, should_flag):
        logic = IbmCloudIamDetector()

        output = logic.analyze_string_content(payload, 1, 'mock_filename')
        assert len(output) == (1 if should_flag else 0)
        if should_flag:
            assert list(output.values())[0].secret_value == CLOUD_IAM_KEY
コード例 #2
0
    def test_verify_bad_response(self):
        responses.add(
            responses.POST,
            'https://iam.cloud.ibm.com/identity/introspect',
            status=404,
        )

        assert IbmCloudIamDetector().verify(
            CLOUD_IAM_KEY_BYTES) == VerifiedResult.UNVERIFIED
コード例 #3
0
    def test_verify_invalid_secret(self):
        responses.add(
            responses.POST,
            'https://iam.cloud.ibm.com/identity/token',
            status=400,
        )

        assert IbmCloudIamDetector().verify(
            CLOUD_IAM_KEY) == VerifiedResult.VERIFIED_FALSE
コード例 #4
0
    def test_verify_valid_secret_byes(self):
        responses.add(
            responses.POST,
            'https://iam.cloud.ibm.com/identity/token',
            status=200,
        )

        IbmCloudIamDetector().verify(
            CLOUD_IAM_KEY_BYTES) == VerifiedResult.VERIFIED_TRUE
コード例 #5
0
    def test_verify_payload_not_json(self):
        responses.add(
            responses.POST,
            'https://iam.cloud.ibm.com/identity/introspect',
            status=200,
            body='not json',
            headers={'content-type': 'not/json'},
        )

        with pytest.raises(Exception):
            IbmCloudIamDetector().verify(CLOUD_IAM_KEY)
コード例 #6
0
    def test_verify_invalid_payload(self):
        responses.add(
            responses.POST,
            'https://iam.cloud.ibm.com/identity/introspect',
            status=200,
            json={'not-the-field': 'we expect'},
            headers={'content-type': 'application/json'},
        )

        assert IbmCloudIamDetector().verify(
            CLOUD_IAM_KEY) == VerifiedResult.UNVERIFIED
コード例 #7
0
    def test_verify_valid_secret_bytes(self):
        responses.add(
            responses.POST,
            'https://iam.cloud.ibm.com/identity/introspect',
            status=200,
            json={'active': True},
            headers={'content-type': 'application/json'},
        )

        assert IbmCloudIamDetector().verify(
            CLOUD_IAM_KEY_BYTES) == VerifiedResult.VERIFIED_TRUE
コード例 #8
0
    def test_analyze_line(self, payload, should_flag):
        logic = IbmCloudIamDetector()

        output = logic.analyze_line(payload, 1, 'mock_filename')
        assert len(output) == (1 if should_flag else 0)