Exemple #1
0
        public override string ComposeUrl(string endpoint, Dictionary <string, string> queries)
        {
            var mapQueries = queries == null ? QueryParameters : queries;
            var urlBuilder = new StringBuilder("");

            urlBuilder.Append(Protocol);
            urlBuilder.Append("://").Append(endpoint);
            if (null != UriPattern)
            {
                urlBuilder.Append(RoaSignatureComposer.ReplaceOccupiedParameters(UriPattern, PathParameters));
            }

            if (-1 == urlBuilder.ToString().IndexOf('?'))
            {
                urlBuilder.Append("?");
            }
            else if (!urlBuilder.ToString().EndsWith("?"))
            {
                urlBuilder.Append("&");
            }

            var query = ConcatQueryString(mapQueries);
            var url   = urlBuilder.Append(query).ToString();

            if (url.EndsWith("?") || url.EndsWith("&"))
            {
                url = url.Substring(0, url.Length - 1);
            }

            return(url);
        }
Exemple #2
0
        public void RefreshSignParameters()
        {
            RpcSignatureComposer.ClearComposer();
            FormatType          formatType = FormatType.JSON;;
            ISignatureComposer  signatureComposer;
            UnmarshallerContext context;

            Dictionary <string, string> parameters = new Dictionary <string, string>
            {
                { "foo", "bar" },
                { "a", "A" },
                { "b", "B" }
            };

            // 覆盖formayType不为null, GetSignertype回调为null的情况
            HmacSHA1Signer hmacSHA1Signer = new HmacSHA1Signer();

            signatureComposer          = RoaSignatureComposer.GetComposer();
            context                    = new UnmarshallerContext();
            context.ResponseDictionary = signatureComposer.RefreshSignParameters(parameters, hmacSHA1Signer, "accessKeyId", formatType);
            Assert.Equal("HMAC-SHA1", context.StringValue("x-acs-signature-method"));

            // 覆盖formayType为null, GetSignerType回调不为null的情况
            SHA256withRSASigner SHA256withRSASigner = new SHA256withRSASigner();

            Assert.NotNull(SHA256withRSASigner.GetSignerType());
            signatureComposer          = new RpcSignatureComposer();
            context.ResponseDictionary = signatureComposer.RefreshSignParameters(parameters, SHA256withRSASigner, "accessKeyId", null);
            Assert.Null(context.StringValue("x-acs-signature-method"));
        }
Exemple #3
0
        public void RefreshSignParameters()
        {
            RoaSignatureComposer.ClearComposer();
            var instance   = new RoaSignatureComposer();
            var parameters = new Dictionary <string, string>
            {
                { "foo", "bar" },
                { "a", "A" },
                { "nullValue", null }
            };
            var mock = new Mock <Signer>();

            mock.Setup(foo => foo.GetSignerType()).Returns("MockSigner");
            var signer  = mock.Object;
            var context = new UnmarshallerContext();

            context.ResponseDictionary =
                instance.RefreshSignParameters(parameters, signer, "accessKeyId", FormatType.JSON);
            Assert.Equal("MockSigner", context.StringValue("x-acs-signature-type"));

            var hmacSHA1Signer = new HmacSHA1Signer();

            context.ResponseDictionary =
                instance.RefreshSignParameters(parameters, hmacSHA1Signer, "accessKeyId", null);
            Assert.Null(context.StringValue("x-acs-signature-type"));
        }
        public void ReplaceOccupiedParameters()
        {
            Dictionary <string, string> tmp = new Dictionary <string, string>
            {
                { "foo", "bar" },
                { "a", "A" },
                { "b", "B" }
            };
            string result = RoaSignatureComposer.ReplaceOccupiedParameters("url?a=[a]&foo=[foo]&b=[b]", tmp);

            Assert.Equal("url?a=A&foo=bar&b=B", result);
        }
 public void RefreshSignParameters()
 {
     Dictionary <string, string> tmp = new Dictionary <string, string>
     {
         { "foo", "bar" },
         { "a", "A" },
         { "b", "B" }
     };
     Signer                      signer     = new HmacSHA1Signer();
     FormatType                  formatType = FormatType.JSON;
     ISignatureComposer          instance   = RoaSignatureComposer.GetComposer();
     Dictionary <String, String> result     = instance.RefreshSignParameters(tmp, signer, "accessKeyId", formatType);
 }
        public void ComposeStringToSign()
        {
            Dictionary <string, string> tmp = new Dictionary <string, string>
            {
                { "foo", "bar" },
                { "a", "A" },
                { "b", "B" }
            };
            MethodType         method   = MethodType.GET;
            Signer             signer   = new HmacSHA1Signer();
            ISignatureComposer instance = RoaSignatureComposer.GetComposer();
            string             result   = instance.ComposeStringToSign(method, "uriPattern", signer, tmp, tmp, tmp);

            Assert.Equal("GET\n\n\n\n\nuriPattern?a=A&b=B&foo=bar", result);
        }
Exemple #7
0
        public void ComposeStringToSign()
        {
            RoaSignatureComposer.ClearComposer();
            var tmp = new Dictionary <string, string>
            {
                { "foo", "bar" },
                { "a", "A" },
                { "nullValue", null }
            };
            var    method   = MethodType.GET;
            Signer signer   = new HmacSHA1Signer();
            var    instance = RoaSignatureComposer.GetComposer();
            var    result   = instance.ComposeStringToSign(method, "www.alibabacloud.com?", signer, tmp, tmp, tmp);

            Assert.Equal("GET\n\n\n\n\nwww.alibabacloud.com?&a=A&foo=bar&nullValue", result);
        }
Exemple #8
0
 private void Initialize()
 {
     Method       = MethodType.GET;
     AcceptFormat = FormatType.RAW;
     Composer     = RoaSignatureComposer.GetComposer();
 }
 private void Initialize()
 {
     this.AcceptFormat = FormatType.RAW;
     this.Composer = RoaSignatureComposer.GetComposer();
 }