public void testSignature() { ParamTestModel instancesInput = new ParamTestModel(); instancesInput.setAction("TestAction"); List <String> imgs = new List <String>(); imgs.Add("test-0001"); imgs.Add("test-0002"); instancesInput.setImageID(imgs); Dictionary <object, object> queryParam = QSParamInvokeUtil.getRequestParams(instancesInput, QSConstant.PARAM_TYPE_QUERY); /*https://api.qc.dev/iaas?access_key_id=QYACCESSKEYIDEXAMPLE&image_id.0=test-0001&image_id.1=test-0002& * // search_word=serch_word_test&signature_method=HmacSHA256&signature_version=1& * // time_stamp=2016-12-02T13%3A07%3A16Z&version=1&signature=r%2FR9TmmnZQWhkEi1gQy5qV9wEPjoJYi9QHSKzliq2eg%3D */ String d = QSSignatureUtil.formatGmtDate(DateTime.Now); String url = QSSignatureUtil.getAuth( "QYACCESSKEYIDEXAMPLE", "wudajefiLSJDWIFJLSD", "GET", "objectTest", queryParam, null); Assert.AreEqual(url.IndexOf("QS QYACCESSKEYIDEXAMPLE:") >= 0, true); }
private HttpWebRequest buildRequest(Dictionary <object, object> context, RequestInputModel Params) { EvnContext evnContext = (EvnContext)context[QSConstant.EVN_CONTEXT_KEY]; string zone = (string)context[QSConstant.PARAM_KEY_REQUEST_ZONE]; Dictionary <object, object> paramsQuery = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_QUERY); Dictionary <object, object> paramsBody = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_BODY); Dictionary <object, object> paramsHeaders = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_HEADER); if (context.ContainsKey(QSConstant.PARAM_KEY_USER_AGENT)) { paramsHeaders.Add(QSConstant.PARAM_KEY_USER_AGENT, context[QSConstant.PARAM_KEY_USER_AGENT]); } String requestApi = (String)context[QSConstant.PARAM_KEY_REQUEST_APINAME]; //string FileBody = GetBodyFile(context[QSConstant.PARAM_KEY_OBJECT_NAME].ToString()).ToString(); paramsHeaders = initHeadContentMd5(requestApi, paramsBody, paramsHeaders); string method = (string)context[QSConstant.PARAM_KEY_REQUEST_METHOD]; string bucketName = (string)context[QSConstant.PARAM_KEY_BUCKET_NAME]; string requestPath = (string)context[QSConstant.PARAM_KEY_REQUEST_PATH]; string objectName = ""; if (context.ContainsKey(QSConstant.PARAM_KEY_OBJECT_NAME)) { objectName = context[QSConstant.PARAM_KEY_OBJECT_NAME].ToString(); } if (!paramsHeaders.ContainsKey(QSConstant.HEADER_PARAM_KEY_CONTENTTYPE)) { paramsHeaders.Add(QSConstant.HEADER_PARAM_KEY_CONTENTTYPE, MimeMapping.GetMimeMapping(objectName)); } if (context.ContainsKey(QSConstant.PARAM_KEY_OBJECT_NAME)) { requestPath = requestPath.Replace(QSConstant.BUCKET_NAME_REPLACE, bucketName); requestPath = requestPath.Replace(QSConstant.OBJECT_NAME_REPLACE, QSStringUtil.urlCharactersEncoding(objectName)); } else { requestPath = requestPath.Replace(QSConstant.BUCKET_NAME_REPLACE, bucketName + "/"); } string authSign = QSSignatureUtil.getAuth( evnContext.getAccessKey(), evnContext.getAccessSecret(), method, requestPath, paramsQuery, paramsHeaders); string requestSuffixPath = getRequestSuffixPath((string)context[QSConstant.PARAM_KEY_REQUEST_PATH], bucketName, objectName); paramsHeaders.Add("Authorization", authSign); logger.Info(authSign); string singedUrl = getSignedUrl( evnContext.getRequestUrl(), zone, bucketName, paramsQuery, requestSuffixPath); if (singedUrl.IndexOf("&upload_id") != -1)//?part_number=0&upload_id=1asfdsf { if (singedUrl.IndexOf("upload_id") > singedUrl.IndexOf("part_number")) { String temp1 = singedUrl.Substring(singedUrl.IndexOf("part_number"), singedUrl.IndexOf("&upload_id") - singedUrl.IndexOf("part_number")); String temp2 = singedUrl.Substring(singedUrl.IndexOf("upload_id"), singedUrl.Length - singedUrl.IndexOf("upload_id")); singedUrl = singedUrl.Substring(0, singedUrl.IndexOf("?") + 1) + temp2 + "&" + temp1; //singedUrl.Replace(temp1, temp2).Replace(temp2,temp1); } } logger.Info(singedUrl); if (QSConstant.PARAM_KEY_REQUEST_API_MULTIPART.Equals(requestApi)) { HttpWebRequest request = QSHttpRequestClient.getInstance() .buildStorMultiUpload( method, paramsBody, singedUrl, paramsHeaders, paramsQuery); return(request); } else { //System.Console.WriteLine(singedUrl); HttpWebRequest request = QSHttpRequestClient.getInstance() .buildStorRequest(method, paramsBody, singedUrl, paramsHeaders); return(request); } }