def af(self, a, b, res, msg):
     if res:
         self.assertTrue(undertest.objectsEqual(a, b), msg=msg)
         self.assertTrue(undertest.objectsEqual(b, a), msg=msg)
     else:
         self.assertFalse(undertest.objectsEqual(a, b), msg=msg)
         self.assertFalse(undertest.objectsEqual(b, a), msg=msg)
예제 #2
0
    def test_singleMatchingCert_MutipleOtherCertsInKong(self):
        self.deleteAllCerts()
        snis = "hosta.com,t.ac.uk,asd.com"

        #Add a cert with SNI=hosta.com
        certID = self.addCert("./examples/certs/server.crt",
                              "./examples/certs/server.key", "hosta.com")
        cartIDx = self.addCert("./examples/certs/server.crt",
                               "./examples/certs/server.key", "hostb.com")
        cartIDx = self.addCert("./examples/certs/server.crt",
                               "./examples/certs/server.key", "hostc.com")
        cartIDx = self.addCert("./examples/certs/server.crt",
                               "./examples/certs/server.key", "hostd.com")
        time.sleep(0.4)

        cmdToExecute = "./scripts/kong_update_cert_where_any_snis_match " + self.kong_server + " " + snis + " ./examples/certs/server.crt ./examples/certs/server.key " + snis
        expectedOutput = "Start of ./scripts/kong_update_cert_where_any_snis_match\n updating where any cert matches any of " + snis + " (kong url " + self.kong_server + ")\n"
        expectedOutput += "Update cert for hosta.com (" + certID + ") - 200\n"
        expectedOutput += "End of ./scripts/kong_update_cert_where_any_snis_match"
        expectedErrorOutput = None

        a = self.executeCommand(cmdToExecute, expectedOutput,
                                expectedErrorOutput, [0], 1, False)

        resp2, respCode2 = self.callKongServiceWithFiles(
            "/certificates/" + certID, None, "get", None, [200], None)
        expected = ["hosta.com"]
        if not python_Testing_Utilities.objectsEqual(resp2["snis"], expected):
            print("Got SNI: " + str(resp2["snis"]))
            print("Expected SNI: " + str(expected))
            self.assertTrue(False, msg="SNIS not correct for cert")
예제 #3
0
    def test_simplaAdd(self):
        self.deleteAllCerts()
        snis = "hosta.com,t.ac.uk,asd.com"

        cmdToExecute = "./scripts/kong_update_or_add_cert_where_any_snis_match " + self.kong_server + " " + snis + " ./examples/certs/server.crt ./examples/certs/server.key hosta.com,t.ac.uk,asd.com"

        expectedOutput = "Start of ./scripts/kong_update_or_add_cert_where_any_snis_match\n"
        expectedOutput += "Found kong version " + self.expected_kong_version + "\n"
        expectedOutput += " updating where any cert matches any of " + snis + " (kong url " + self.kong_server + ")\n"
        expectedOutput += "Create cert for " + snis + " - 201\n"
        expectedOutput += "End of ./scripts/kong_update_or_add_cert_where_any_snis_match"
        expectedErrorOutput = None

        a = self.executeCommand(cmdToExecute, expectedOutput,
                                expectedErrorOutput, [0], 1, False)

        resp2, respCode2 = self.callKongServiceWithFiles(
            "/certificates/", None, "get", None, [200], None)
        self.assertEqual(len(resp2["data"]),
                         1,
                         msg="Wrong number of certs in server")

        if not python_Testing_Utilities.objectsEqual(resp2["data"][0]["snis"],
                                                     snis.split(",")):
            print("Got SNI: " + str(resp2["data"][0]["snis"]))
            print("Expected SNI: " + snis)
            self.assertTrue(False, msg="SNIS not correct for cert")
  def assertVersionRunningList(self, lis, scriptoutput, ws_name=ws_nameGLOB, skipImageCheck=False):
    self._assert_valid_list(lis)
    verDigits = -1
    if len(lis) > 0:
      verDigits = len(lis[0].split("."))
    required_service_names = []
    for x in lis:
      required_service_names.append(ws_name + "_" + x.replace('.','_'))

    running_service_names = []
    for service in client.services.list():
      if isServiceThisWS(service.name, ws_name, verDigits):
        running_service_names.append(service.name)

    if not python_Testing_Utilities.objectsEqual(required_service_names,running_service_names):
      if scriptoutput != None:
        self.printExecuteCommandOutput(scriptoutput)
      print("Expected services running:" + str(required_service_names))
      print("Actual services running:" + str(running_service_names))
      self.assertTrue(False,msg="Wrong services running")

    if skipImageCheck:
      return

    #Finally make sure images have been deleted
    # no need to check for created images as if they are not there
    # the service would not run
    for image in client.images.list():
      for tag in image.tags:
        if tag.startswith(image_prefix + ws_name + ":"):
          ver = tag[(len(image_prefix + ws_name) + 1):]
          if ver not in lis:
            if scriptoutput != None:
              self.printExecuteCommandOutput(scriptoutput)
            self.assertTrue(False,msg="Image " + tag + " was not removed")
예제 #5
0
    def test_list_all_objectTypes(self):
        objectStoreType = self.setupUnevenData()

        def getObjTpeLis(context):
            return context.list_all_objectTypes()

        t1ObjectLis = objectStoreType.executeInsideConnectionContext(
            testTenant1, getObjTpeLis)
        t2ObjectLis = objectStoreType.executeInsideConnectionContext(
            testTenant2, getObjTpeLis)

        self.assertTrue(objectsEqual(t1ObjectLis, tenant1ObjectsToUse),
                        msg="Wrong object list supplied for Tenant1 got - " +
                        str(t1ObjectLis))
        self.assertTrue(objectsEqual(t2ObjectLis, tenant2ObjectsToUse),
                        msg="Wrong object list supplied for Tenant2 got - " +
                        str(t2ObjectLis))
  def assertImageList(self, lis, ws_name=ws_nameGLOB):
    self._assert_valid_list(lis)
    present_images = []
    for image in client.images.list():
      for tag in image.tags:
        if tag.startswith(image_prefix + ws_name + ":"):
          x = tag.split(":")
          present_images.append(x[1])

    if not python_Testing_Utilities.objectsEqual(present_images,lis):
      print("present_images:", present_images)
      print("expected present images:", lis)
      self.assertFalse(True)
예제 #7
0
        def dbfn2(storeConnection):
            def outputFN(item):
                return item[0]

            paginatedParamValues = {
                'offset': 0,
                'pagesize': 20,
                'query': '',
                'sort': None
            }
            res = storeConnection.getPaginatedResult(objectType2,
                                                     paginatedParamValues,
                                                     outputFN)
            expectedRes = []
            assertCorrectPaginationResult(self, res, 0, 20, 0)

            a = list(map(lambda x: json.dumps(x), res['result']))
            b = list(map(lambda x: json.dumps(x), expectedRes))
            self.assertTrue(objectsEqual(a, b), msg="Wrong result")
예제 #8
0
    def addCert(self, certfile, privkeyfile, snis):
        files = {
            'cert': (certfile, open(certfile, 'rb')),
            'key': (privkeyfile, open(privkeyfile, 'rb')),
            'snis': (None, snis)
        }
        headers = {}
        resp, respCode = self.callKongServiceWithFiles("/certificates",
                                                       headers, "post", files,
                                                       [201], None)

        if self.expected_kong_version == "1.1.2":
            for x in snis.split(","):
                data = {'name': x}
                respSNI, respCodeSNI = self.callKongServiceWithFiles(
                    "/certificates/" + resp["id"] + "/snis", headers, "post",
                    None, [201], data)

        #MAKE SURE CERT HAS BEEN ADDED
        resp2, respCode2 = self.callKongServiceWithFiles(
            "/certificates", headers, "get", None, [200], None)
        found = False
        for x in resp2["data"]:
            if x["id"] == resp["id"]:
                #resp3, respCode3 = self.callKongServiceWithFiles("/certificates/" + x["id"] + "/snis", headers, "get", None, [200])
                #print("resp3", resp3)
                if not python_Testing_Utilities.objectsEqual(
                        x["snis"], snis.split(",")):
                    print("Got SNI: " + str(x["snis"]))
                    print("Expected SNI: " + snis)
                    self.assertTrue(False, msg="SNIS not correct for cert")
                return resp["id"]
        self.assertTrue(
            False,
            msg=
            "After sucessful create of certificate a get request did not return it"
        )
 def test_numbers(self):
     self.assertTrue(undertest.objectsEqual(1, 1), msg="Nubers Equal")
     self.assertFalse(undertest.objectsEqual(1, 2), msg="Nubers Equal")
 def test_strings(self):
     self.assertTrue(undertest.objectsEqual("A", "A"), msg="Strings Equal")
     self.assertFalse(undertest.objectsEqual("A", "B"), msg="Strings Equal")
 def test_none(self):
     self.assertTrue(undertest.objectsEqual(None, None),
                     msg="Different None types")
 def test_differentTypes(self):
     self.assertFalse(undertest.objectsEqual("A", 123),
                      msg="Different types should not be Equal")