コード例 #1
0
	def _check_node_value(self, t, xpath, expected):
		try:
			actual = xmlutil.get_node_value(t, xpath)
			if actual != expected:
				Printer.error("Node at XPath %s has actual value %s, expected value %s" % (xpath, actual, expected))

		except NodeNotFoundException:
			Printer.error("Node at XPath %s was not found in the response" % xpath)
コード例 #2
0
    def _check_node_value(self, t, xpath, expected):
        try:
            actual = xmlutil.get_node_value(t, xpath)
            if actual != expected:
                Printer.error(
                    "Node at XPath %s has actual value %s, expected value %s" %
                    (xpath, actual, expected))

        except NodeNotFoundException:
            Printer.error("Node at XPath %s was not found in the response" %
                          xpath)
コード例 #3
0
	def _get_node_value(self, t, xpath):
		try:
			return xmlutil.get_node_value(t, xpath)
		except NodeNotFoundException:
			return None
コード例 #4
0
	def sso(self):
		Printer.start_test("SSO with valid timestamp and token")
		(status, response) = self.client.perform_request(
				"subscriptions/%s/cloudservices/%s/resources/%s/%s/SsoToken" % (
						self.config["subscription_id"],
						self.config["cloud_service_name"],
						self.config["resource_type"],
						self.config["resource_name"]
					),
				"POST",
				None,
				validate_xml=True
			)

		if status in [200, 201]:
			Printer.success("SSO token request succeeded.")
			Printer.info("Checking XML")
		else:
			Printer.error("SSO token request failed with HTTP status code %s" % status)
			return

		t = xmlutil.get_subtree_from_xml_string(response)
		self._check_node_exists(t, "./{0}SsoToken/TimeStamp")
		self._check_node_exists(t, "./{0}SsoToken/Token")

		fragment = urllib.urlencode(
				{
					"token": xmlutil.get_node_value(t, "./{0}Token"),
					"timestamp": xmlutil.get_node_value(t, "./{0}TimeStamp")
				}
			)

		(status, response) = self.client.perform_request(
				"?subid=%s&cloudservicename=%s&resourcetype=%s&resourcename=%s&%s" % (
			 		self.config["subscription_id"], 
			 		self.config["cloud_service_name"],
			  		self.config["resource_type"],
			 		self.config["resource_name"],
			 		fragment
					),
				"GET",
				None,
				uri_type="sso",
				validate_xml=False
			)

		if status in [200, 201]:
			Printer.success("SSO login succeeded.")
		else:
			Printer.error("SSO login request failed with HTTP status code %s" % status)
			return


		Printer.start_test("SSO with expired timestamp")
		given_timestamp = iso8601.parse_date(xmlutil.get_node_value(t, "./{0}TimeStamp"))
		expired_timestamp = given_timestamp + timedelta(seconds=60*10)
		
		fragment = urllib.urlencode(
				{
					"token": xmlutil.get_node_value(t, "./{0}Token"),
					"timestamp": str(expired_timestamp)
				}
			)

		(status, response) = self.client.perform_request(
				"sso?subid=%s&cloudservicename=%s&resourcetype=%s&resourcename=%s&%s" % (
			 		self.config["subscription_id"], 
			 		self.config["cloud_service_name"],
			  		self.config["resource_type"],
			 		self.config["resource_name"],
			 		fragment
					),
				"GET",
				None,
				uri_type="sso",
				validate_xml=False
			)

		if status in [200, 201]:
			Printer.error("SSO login with expired timestamp succeeded.")
		else:
			Printer.success("SSO login with expired timestamp failed with error code %s" % status)
			return
コード例 #5
0
 def _get_node_value(self, t, xpath):
     try:
         return xmlutil.get_node_value(t, xpath)
     except NodeNotFoundException:
         return None
コード例 #6
0
    def sso(self):
        Printer.start_test("SSO with valid timestamp and token")
        (status, response) = self.client.perform_request(
            "subscriptions/%s/cloudservices/%s/resources/%s/%s/SsoToken" %
            (self.config["subscription_id"], self.config["cloud_service_name"],
             self.config["resource_type"], self.config["resource_name"]),
            "POST",
            None,
            validate_xml=True)

        if status in [200, 201]:
            Printer.success("SSO token request succeeded.")
            Printer.info("Checking XML")
        else:
            Printer.error("SSO token request failed with HTTP status code %s" %
                          status)
            return

        t = xmlutil.get_subtree_from_xml_string(response)
        self._check_node_exists(t, "./{0}SsoToken/TimeStamp")
        self._check_node_exists(t, "./{0}SsoToken/Token")

        fragment = urllib.urlencode({
            "token":
            xmlutil.get_node_value(t, "./{0}Token"),
            "timestamp":
            xmlutil.get_node_value(t, "./{0}TimeStamp")
        })

        (status, response) = self.client.perform_request(
            "?subid=%s&cloudservicename=%s&resourcetype=%s&resourcename=%s&%s"
            % (self.config["subscription_id"],
               self.config["cloud_service_name"], self.config["resource_type"],
               self.config["resource_name"], fragment),
            "GET",
            None,
            uri_type="sso",
            validate_xml=False)

        if status in [200, 201]:
            Printer.success("SSO login succeeded.")
        else:
            Printer.error("SSO login request failed with HTTP status code %s" %
                          status)
            return

        Printer.start_test("SSO with expired timestamp")
        given_timestamp = iso8601.parse_date(
            xmlutil.get_node_value(t, "./{0}TimeStamp"))
        expired_timestamp = given_timestamp + timedelta(seconds=60 * 10)

        fragment = urllib.urlencode({
            "token":
            xmlutil.get_node_value(t, "./{0}Token"),
            "timestamp":
            str(expired_timestamp)
        })

        (status, response) = self.client.perform_request(
            "sso?subid=%s&cloudservicename=%s&resourcetype=%s&resourcename=%s&%s"
            % (self.config["subscription_id"],
               self.config["cloud_service_name"], self.config["resource_type"],
               self.config["resource_name"], fragment),
            "GET",
            None,
            uri_type="sso",
            validate_xml=False)

        if status in [200, 201]:
            Printer.error("SSO login with expired timestamp succeeded.")
        else:
            Printer.success(
                "SSO login with expired timestamp failed with error code %s" %
                status)
            return