Пример #1
0
 def test_reenroll_unreachable_server_address(self):
     """Test reenroll unreachable server address.
     """
     self._ca_server_address = "test:80"
     ca_service = CAService("http://" + self._ca_server_address)
     with self.assertRaises(Exception):
         ca_service.reenroll(self._enrollment)
Пример #2
0
 def test_enroll_with_generated_csr_success(self):
     """Test enroll with generated csr success.
     """
     ca_service = CAService("http://" + self._ca_server_address)
     enrollment = ca_service.enroll(self._enrollment_id,
                                    self._enrollment_secret)
     self.assertTrue(enrollment.cert
                     .startswith(b"-----BEGIN CERTIFICATE-----"))
Пример #3
0
 def test_register_success(self):
     """Test register success.
     """
     ca_service = CAService("http://" + self._ca_server_address)
     enrollment = ca_service.enroll(self._enrollment_id,
                                    self._enrollment_secret)
     # use a random username for registering for avoiding already register
     # issues when test suite ran several times
     username = get_random_username()
     secret = enrollment.register(username, 'pass')
     self.assertTrue(secret == 'pass')
Пример #4
0
    def test_already_register(self):
        """Test register a second time.
        """
        ca_service = CAService("http://" + self._ca_server_address)
        enrollment = ca_service.enroll(self._enrollment_id,
                                       self._enrollment_secret)
        # use a random username for registering for avoiding already register
        # issues when test suite ran several times
        username = get_random_username()
        enrollment.register(username)

        # register a second time
        with self.assertRaises(Exception):
            enrollment.register(username)
Пример #5
0
 def test_revoke_unreachable_server_address(self):
     """Test revoke unreachable server address.
     """
     self._ca_server_address = "test:80"
     ca_service = CAService("http://" + self._ca_server_address)
     enrollment = Enrollment(None, '', ca_service)
     with self.assertRaises(Exception):
         enrollment.revoke('foo')
Пример #6
0
    def setUp(self):
        self._enrollment_id = ENROLLMENT_ID
        self._enrollment_secret = ENROLLMENT_SECRET
        if os.getenv("CA_ADDR"):
            self._ca_server_address = os.getenv("CA_ADDR")
        else:
            self._ca_server_address = "localhost:7054"
        self.compose_file_path = os.path.normpath(
            os.path.join(os.path.dirname(__file__),
                         "../fixtures/ca/docker-compose.yml"))

        self.start_test_env()

        self._ca_service = CAService("http://" + self._ca_server_address)
        id = self._enrollment_id
        secret = self._enrollment_secret
        self._adminEnrollment = self._ca_service.enroll(id, secret)
        self._affiliationService = self._ca_service.newAffiliationService()
Пример #7
0
    def test_reenroll_success(self):
        """Test revoke success.
        """
        ca_service = CAService("http://" + self._ca_server_address)
        enrollment = ca_service.enroll(self._enrollment_id,
                                       self._enrollment_secret)
        # use a random username for registering for avoiding already register
        # issues when test suite ran several times
        username = get_random_username()
        secret = enrollment.register(username)

        # enroll new user
        enrollment = ca_service.enroll(username, secret)

        # reenroll
        reenrollment = ca_service.reenroll(enrollment)

        self.assertTrue(reenrollment.cert
                        .startswith(b"-----BEGIN CERTIFICATE-----"))
Пример #8
0
    def test_genCRL_success(self):
        """Test revoke success.
        """
        ca_service = CAService("http://" + self._ca_server_address)
        enrollment = ca_service.enroll(self._enrollment_id,
                                       self._enrollment_secret)
        # use a random username for registering for avoiding already register
        # issues when test suite ran several times
        username = get_random_username()
        secret = enrollment.register(username)

        # enroll new user
        ca_service.enroll(username, secret)

        # now revoke
        enrollment.revoke(username)

        # gen CRL
        try:
            enrollment.generateCRL()
        except Exception as e:
            self.fail("generateCRL fails: {0}".format(e))
Пример #9
0
    def test_revoke_success(self):
        """Test revoke success.
        """
        ca_service = CAService("http://" + self._ca_server_address)
        enrollment = ca_service.enroll(self._enrollment_id,
                                       self._enrollment_secret)
        # use a random username for registering for avoiding already register
        # issues when test suite ran several times
        username = get_random_username()
        secret = enrollment.register(username)

        # enroll new user
        ca_service.enroll(username, secret)

        # now revoke
        RevokedCerts, CRL = enrollment.revoke(username)
        self.assertTrue(CRL == '')
        self.assertTrue(len(RevokedCerts) == 1)
        self.assertTrue('Serial' in RevokedCerts[0])
        self.assertTrue('AKI' in RevokedCerts[0])
        self.assertTrue(len(RevokedCerts[0]['AKI']) > 0)
        self.assertTrue(len(RevokedCerts[0]['Serial']) > 0)
class CertificateServiceTest(unittest.TestCase):
    """Test for ca module. """
    def setUp(self):
        self._enrollment_id = ENROLLMENT_ID
        self._enrollment_secret = ENROLLMENT_SECRET
        if os.getenv("CA_ADDR"):
            self._ca_server_address = os.getenv("CA_ADDR")
        else:
            self._ca_server_address = "localhost:7054"
        self.compose_file_path = os.path.normpath(
            os.path.join(os.path.dirname(__file__),
                         "../fixtures/ca/docker-compose.yml"))

        self.start_test_env()

        self._ca_service = CAService("http://" + self._ca_server_address)
        id = self._enrollment_id
        secret = self._enrollment_secret
        self._adminEnrollment = self._ca_service.enroll(id, secret)
        self._certificateService = self._ca_service.newCertificateService()

    def tearDown(self):
        self.shutdown_test_env()

    def start_test_env(self):
        cli_call(["docker-compose", "-f", self.compose_file_path, "up", "-d"])
        time.sleep(5)

    def shutdown_test_env(self):
        cli_call(["docker-compose", "-f", self.compose_file_path, "down"])

    def test_get_success(self):
        """Test create success.
        """
        res = self._certificateService.getCertificates(self._adminEnrollment)

        self.assertTrue(res['success'] is True)
        self.assertTrue(len(res['result']) > 0)
Пример #11
0
    def test_reenroll_after_revoke_success(self):
        """Test revoke success.
        """
        ca_service = CAService("http://" + self._ca_server_address)
        enrollment = ca_service.enroll(self._enrollment_id,
                                       self._enrollment_secret)
        # use a random username for registering for avoiding already register
        # issues when test suite ran several times
        username = get_random_username()
        secret = enrollment.register(username)

        # enroll new user
        enrollment = ca_service.enroll(username, secret)

        # now revoke
        enrollment.revoke(username)

        # reenroll
        with self.assertRaises(Exception):
            ca_service.reenroll(enrollment)
Пример #12
0
from hfc.fabric_network import wallet
from hfc.fabric_ca.caservice import CAClient, CAService

# Netherlands user
casvc = CAService(target="http://192.168.39.209:31700")
adminNlEnrollment = casvc.enroll(
    "admin", "adminpw")  # now local will have the admin enrollment
secret = adminNlEnrollment.register("user1Nl")  # register a user to ca
user1NlEnrollment = casvc.enroll(
    "user1Nl", secret)  # now local will have the user enrollment
new_wallet = wallet.FileSystenWallet(
)  # Creates default wallet at ./tmp/hfc-kvs
user_identity_nl = wallet.Identity(
    "user1Nl",
    user1NlEnrollment)  # Creates a new Identity of the enrolled user
user_identity_nl.CreateIdentity(
    new_wallet)  # Stores this identity in the FileSystemWallet
user1Nl = new_wallet.create_user(
    "user1Nl", "Netherlands", "NetherlandsMSP"
)  # Returns an instance of the user object with the newly created credentials

# # Spain user
# casvc = CAService(target="http://172.17.0.2:31701")
# adminEsEnrollment = casvc.enroll("admin", "adminpw") # now local will have the admin enrollment
# secret = adminEsEnrollment.register("user1Es") # register a user to ca
# user1EsEnrollment = casvc.enroll("user1Es", secret) # now local will have the user enrollment
# # new_wallet = wallet.FileSystenWallet() # Creates default wallet at ./tmp/hfc-kvs
# user_identity_es = wallet.Identity("user1Es", user1EsEnrollment) # Creates a new Identity of the enrolled user
# user_identity_es.CreateIdentity(new_wallet) # Stores this identity in the FileSystemWallet
# user1Es = new_wallet.create_user("user1Es", "Spain", "SpainMSP") # Returns an instance of the user object with the newly created credentials
Пример #13
0
class AffiliationServiceTest(unittest.TestCase):
    """Test for ca module. """
    def setUp(self):
        self._enrollment_id = ENROLLMENT_ID
        self._enrollment_secret = ENROLLMENT_SECRET
        if os.getenv("CA_ADDR"):
            self._ca_server_address = os.getenv("CA_ADDR")
        else:
            self._ca_server_address = "localhost:7054"
        self.compose_file_path = os.path.normpath(
            os.path.join(os.path.dirname(__file__),
                         "../fixtures/ca/docker-compose.yml"))

        self.start_test_env()

        self._ca_service = CAService("http://" + self._ca_server_address)
        id = self._enrollment_id
        secret = self._enrollment_secret
        self._adminEnrollment = self._ca_service.enroll(id, secret)
        self._affiliationService = self._ca_service.newAffiliationService()

    def tearDown(self):
        self.shutdown_test_env()

    def start_test_env(self):
        cli_call(["docker-compose", "-f", self.compose_file_path, "up", "-d"])
        time.sleep(5)

    def shutdown_test_env(self):
        cli_call(["docker-compose", "-f", self.compose_file_path, "down"])

    def test_create_success(self):
        """Test create success.
        """
        affiliation = get_affiliation()
        res = self._affiliationService.create(self._adminEnrollment,
                                              affiliation)

        self.assertTrue(res['success'] is True)
        self.assertTrue(res['result']['name'] == affiliation)

    def test_getOne_success(self):
        """Test getOne success.
        """
        affiliation = get_affiliation()
        self._affiliationService.create(self._adminEnrollment, affiliation)

        res = self._affiliationService.getOne(affiliation,
                                              self._adminEnrollment)

        self.assertTrue(res['success'] is True)
        self.assertTrue(res['result']['name'] == affiliation)

    def test_getAll_success(self):
        """Test getAll success.
        """
        affiliation = get_affiliation()
        self._affiliationService.create(self._adminEnrollment, affiliation)

        res = self._affiliationService.getAll(self._adminEnrollment)

        self.assertTrue(res['success'] is True)
        self.assertTrue(len(res['result']['affiliations']) > 0)

    def test_delete_success(self):
        """Test delete success.
        """
        affiliation = get_affiliation()
        self._affiliationService.create(self._adminEnrollment, affiliation)

        res = self._affiliationService.delete(affiliation,
                                              self._adminEnrollment)

        self.assertTrue(res['success'] is True)

    def test_update_success(self):
        """Test update success.
        """
        affiliation = get_affiliation()
        self._affiliationService.create(self._adminEnrollment, affiliation)

        res = self._affiliationService.update(affiliation,
                                              self._adminEnrollment,
                                              name=affiliation + 'bis')

        self.assertTrue(res['success'] is True)
        self.assertTrue(res['result']['name'] == affiliation + 'bis')
Пример #14
0
class IdentityServiceTest(unittest.TestCase):
    """Test for ca module. """
    def setUp(self):
        self._enrollment_id = ENROLLMENT_ID
        self._enrollment_secret = ENROLLMENT_SECRET
        if os.getenv("CA_ADDR"):
            self._ca_server_address = os.getenv("CA_ADDR")
        else:
            self._ca_server_address = "localhost:7054"
        self.compose_file_path = os.path.normpath(
            os.path.join(os.path.dirname(__file__),
                         "../fixtures/ca/docker-compose.yml"))

        self.start_test_env()

        self._ca_service = CAService("http://" + self._ca_server_address)
        id = self._enrollment_id
        secret = self._enrollment_secret
        self._adminEnrollment = self._ca_service.enroll(id, secret)
        self._identityService = self._ca_service.newIdentityService()

    def tearDown(self):
        self.shutdown_test_env()

    def start_test_env(self):
        cli_call(["docker-compose", "-f", self.compose_file_path, "up", "-d"])
        time.sleep(5)

    def shutdown_test_env(self):
        cli_call(["docker-compose", "-f", self.compose_file_path, "down"])

    def test_create_success(self):
        """Test create success.
        """
        username = get_random_username()
        secret = self._identityService.create(self._adminEnrollment,
                                              username,
                                              enrollmentSecret='pass')
        self.assertTrue(secret == 'pass')

    def test_getOne_success(self):
        """Test getOne success.
        """
        username = get_random_username()
        self._identityService.create(self._adminEnrollment, username)

        res = self._identityService.getOne(username, self._adminEnrollment)
        self.assertTrue(res['result']['id'] == username)
        self.assertTrue(res['success'] is True)

    def test_getAll_success(self):
        """Test getAll success.
        """
        username = get_random_username()
        self._identityService.create(self._adminEnrollment, username)

        res = self._identityService.getAll(self._adminEnrollment)
        self.assertTrue(len(res['result']['identities']) > 0)
        self.assertTrue(res['success'] is True)

    def test_delete_success(self):
        """Test delete success.
        """
        username = get_random_username()
        self._identityService.create(self._adminEnrollment, username)

        res = self._identityService.delete(username, self._adminEnrollment)

        self.assertTrue(res['success'] is True)

    def test_update_success(self):
        """Test update success.
        """
        username = get_random_username()
        self._identityService.create(self._adminEnrollment, username)

        res = self._identityService.update(username,
                                           self._adminEnrollment,
                                           maxEnrollments=3)

        self.assertTrue(res['result']['id'] == username)
        self.assertTrue(res['result']['max_enrollments'] == 3)
        self.assertTrue(res['success'] is True)
Пример #15
0
 def test_reenroll_wrong_attr_req(self):
     """Test reenroll wrong attr_req
     """
     ca_service = CAService("http://" + self._ca_server_address)
     with self.assertRaises(AttributeError):
         ca_service.reenroll(self._enrollment, [''])
Пример #16
0
 def test_reenroll_no_user(self):
     """Test reenroll no user
     """
     ca_service = CAService("http://" + self._ca_server_address)
     with self.assertRaises(ValueError):
         ca_service.reenroll('foo')