Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/pop_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
working-directory: alibabacloud-gateway-pop/python
jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
fail-fast: false

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install setuptools urllib3==1.26.20 alibabacloud-tea coverage pytest alibabacloud-credentials==0.3.6 && python setup.py install
run: pip install setuptools urllib3==1.26.20 'cryptography>=3.0.0, <45.0.0' alibabacloud-tea alibabacloud_darabonba_encode_util alibabacloud_darabonba_signature_util alibabacloud_gateway_spi alibabacloud_tea_util alibabacloud_openapi_util alibabacloud_endpoint_util alibabacloud_darabonba_string alibabacloud_darabonba_map alibabacloud_darabonba_array alibabacloud_tea_xml coverage pytest alibabacloud-credentials && python setup.py install
- name: Test with unittest
run: |
coverage run --source="./alibabacloud_tea_util" -m pytest tests/test_*
coverage run -m unittest discover
- name: CodeCov
run: bash <(curl -s https://codecov.io/bash) -cF python

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
22 changes: 16 additions & 6 deletions alibabacloud-gateway-pop/csharp/core/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,18 +605,28 @@ public string BuildCanonicalizedHeaders(Dictionary<string, string> headers)
public List<string> GetSignedHeaders(Dictionary<string, string> headers)
{
List<string> headersArray = AlibabaCloud.DarabonbaMap.MapUtil.KeySet(headers);
List<string> sortedHeadersArray = AlibabaCloud.DarabonbaArray.ArrayUtil.AscSort(headersArray);
List<string> newHeadersArray = new List<string>
{
};

foreach (var key in headersArray) {
string lowerKey = AlibabaCloud.DarabonbaString.StringUtil.ToLower(key);
string value = headers.Get(key);
if (!AlibabaCloud.TeaUtil.Common.IsUnset(value))
{
AlibabaCloud.DarabonbaArray.ArrayUtil.Append(newHeadersArray, lowerKey);
}
}
List<string> sortedHeadersArray = AlibabaCloud.DarabonbaArray.ArrayUtil.AscSort(newHeadersArray);
string tmp = "";
string separator = "";

foreach (var key in sortedHeadersArray) {
string lowerKey = AlibabaCloud.DarabonbaString.StringUtil.ToLower(key);
if (AlibabaCloud.DarabonbaString.StringUtil.HasPrefix(lowerKey, "x-acs-") || AlibabaCloud.DarabonbaString.StringUtil.Equals(lowerKey, "host") || AlibabaCloud.DarabonbaString.StringUtil.Equals(lowerKey, "content-type"))
if (AlibabaCloud.DarabonbaString.StringUtil.HasPrefix(key, "x-acs-") || AlibabaCloud.DarabonbaString.StringUtil.Equals(key, "host") || AlibabaCloud.DarabonbaString.StringUtil.Equals(key, "content-type"))
{
string value = headers.Get(key);
if (!AlibabaCloud.TeaUtil.Common.IsUnset(value) && !AlibabaCloud.DarabonbaString.StringUtil.Contains(tmp, lowerKey))
if (!AlibabaCloud.DarabonbaString.StringUtil.Contains(tmp, key))
{
tmp = "" + tmp + separator + lowerKey;
tmp = "" + tmp + separator + key;
separator = ";";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.1.1.0")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyVersion("0.1.2.0")]
[assembly: AssemblyFileVersion("0.1.2.0")]
68 changes: 67 additions & 1 deletion alibabacloud-gateway-pop/csharp/tests/UnitTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using AlibabaCloud.GatewayPop;

using Xunit;
Expand Down Expand Up @@ -31,5 +32,70 @@ public void Test_GetRegion()
Assert.Equal("cn-hangzhou-acdr-ut-1", client.GetRegion("test", "test-inner.cn-hangzhou-acdr-ut-1.aliyuncs.com", null));
Assert.Equal("cn-edge-1", client.GetRegion("test", "test-inner.cn-edge-1.aliyuncs.com", null));
}

[Fact]
public void Test_GetSignedHeaders()
{
Client client = new Client();

// 测试空headers
var emptyHeaders = new Dictionary<string, string>();
var result = client.GetSignedHeaders(emptyHeaders);
Assert.Equal(1, result.Count);

// 测试只包含需要签名的headers
var headers = new Dictionary<string, string>
{
{ "host", "example.com" },
{ "Host", "example.com" },
{ "content-type", "application/json" },
{ "x-acs-action", "TestAction" }
};
result = client.GetSignedHeaders(headers);
Assert.Equal(3, result.Count);
Assert.Equal("content-type", result[0]);
Assert.Equal("host", result[1]);
Assert.Equal("x-acs-action", result[2]);

// 测试包含不需要签名的headers
var headersWithIgnore = new Dictionary<string, string>
{
{ "host", "example.com" },
{ "content-type", "application/json" },
{ "x-acs-action", "TestAction" },
{ "authorization", "Bearer token" },
{ "user-agent", "C#-client" }
};
result = client.GetSignedHeaders(headersWithIgnore);
Assert.Equal(3, result.Count);
Assert.Equal("content-type", result[0]);
Assert.Equal("host", result[1]);
Assert.Equal("x-acs-action", result[2]);

// 测试空值header
var headersWithEmpty = new Dictionary<string, string>
{
{ "host", "example.com" },
{ "content-type", null },
{ "x-acs-action", "TestAction" }
};
result = client.GetSignedHeaders(headersWithEmpty);
Assert.Equal(2, result.Count);
Assert.Equal("host", result[0]);
Assert.Equal("x-acs-action", result[1]);

// 测试大小写不敏感
var headersWithCase = new Dictionary<string, string>
{
{ "HOST", "example.com" },
{ "Content-Type", "application/json" },
{ "X-Acs-Action", "TestAction" }
};
result = client.GetSignedHeaders(headersWithCase);
Assert.Equal(3, result.Count);
Assert.Equal("content-type", result[0]);
Assert.Equal("host", result[1]);
Assert.Equal("x-acs-action", result[2]);
}
}
}
}
19 changes: 13 additions & 6 deletions alibabacloud-gateway-pop/golang/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,22 @@ func (client *Client) BuildCanonicalizedHeaders(headers map[string]*string) (_re

func (client *Client) GetSignedHeaders(headers map[string]*string) (_result []*string) {
headersArray := map_.KeySet(headers)
sortedHeadersArray := array.AscSort(headersArray)
newHeadersArray := []*string{}
for _, key := range headersArray {
lowerKey := string_.ToLower(key)
value := headers[tea.StringValue(key)]
if !tea.BoolValue(util.IsUnset(value)) {
newHeadersArray = append(newHeadersArray, lowerKey)
}

}
sortedHeadersArray := array.AscSort(newHeadersArray)
tmp := tea.String("")
separator := tea.String("")
for _, key := range sortedHeadersArray {
lowerKey := string_.ToLower(key)
if tea.BoolValue(string_.HasPrefix(lowerKey, tea.String("x-acs-"))) || tea.BoolValue(string_.Equals(lowerKey, tea.String("host"))) || tea.BoolValue(string_.Equals(lowerKey, tea.String("content-type"))) {
value := headers[tea.StringValue(key)]
if !tea.BoolValue(util.IsUnset(value)) && !tea.BoolValue(string_.Contains(tmp, lowerKey)) {
tmp = tea.String(tea.StringValue(tmp) + tea.StringValue(separator) + tea.StringValue(lowerKey))
if tea.BoolValue(string_.HasPrefix(key, tea.String("x-acs-"))) || tea.BoolValue(string_.Equals(key, tea.String("host"))) || tea.BoolValue(string_.Equals(key, tea.String("content-type"))) {
if !tea.BoolValue(string_.Contains(tmp, key)) {
tmp = tea.String(tea.StringValue(tmp) + tea.StringValue(separator) + tea.StringValue(key))
separator = tea.String(";")
}

Expand Down
47 changes: 47 additions & 0 deletions alibabacloud-gateway-pop/golang/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,50 @@ func Test_GetRegion(t *testing.T) {
utils.AssertEqual(t, "cn-hangzhou-acdr-ut-1", tea.StringValue(client.GetRegion(tea.String("test"), tea.String("test-inner.cn-hangzhou-acdr-ut-1.aliyuncs.com"), nil)))
utils.AssertEqual(t, "cn-edge-1", tea.StringValue(client.GetRegion(tea.String("test"), tea.String("test-inner.cn-edge-1.aliyuncs.com"), nil)))
}

func Test_GetSignedHeaders(t *testing.T) {
client, err := NewClient()
utils.AssertNil(t, err)

// 测试空headers
result := client.GetSignedHeaders(make(map[string]*string))
utils.AssertEqual(t, 1, len(result))

// 测试只包含需要签名的headers
headers := map[string]*string{
"host": tea.String("example.com"),
"Host": tea.String("example.com"),
"content-type": tea.String("application/json"),
"x-acs-action": tea.String("TestAction"),
}
result = client.GetSignedHeaders(headers)
utils.AssertEqual(t, 3, len(result))
utils.AssertEqual(t, "content-type", tea.StringValue(result[0]))
utils.AssertEqual(t, "host", tea.StringValue(result[1]))
utils.AssertEqual(t, "x-acs-action", tea.StringValue(result[2]))

// 测试包含不需要签名的headers
headersWithIgnore := map[string]*string{
"host": tea.String("example.com"),
"content-type": tea.String("application/json"),
"x-acs-action": tea.String("TestAction"),
"authorization": tea.String("Bearer token"),
"user-agent": tea.String("Go-client"),
}
result = client.GetSignedHeaders(headersWithIgnore)
utils.AssertEqual(t, 3, len(result))
utils.AssertEqual(t, "content-type", tea.StringValue(result[0]))
utils.AssertEqual(t, "host", tea.StringValue(result[1]))
utils.AssertEqual(t, "x-acs-action", tea.StringValue(result[2]))

// 测试空值header
headersWithEmpty := map[string]*string{
"host": tea.String("example.com"),
"content-type": nil,
"x-acs-action": tea.String("TestAction"),
}
result = client.GetSignedHeaders(headersWithEmpty)
utils.AssertEqual(t, 2, len(result))
utils.AssertEqual(t, "host", tea.StringValue(result[0]))
utils.AssertEqual(t, "x-acs-action", tea.StringValue(result[1]))
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,22 @@ public String buildCanonicalizedHeaders(java.util.Map<String, String> headers) t

public java.util.List<String> getSignedHeaders(java.util.Map<String, String> headers) throws Exception {
java.util.List<String> headersArray = com.aliyun.darabonba.map.Client.keySet(headers);
java.util.List<String> sortedHeadersArray = com.aliyun.darabonba.array.Client.ascSort(headersArray);
java.util.List<String> newHeadersArray = new java.util.ArrayList<>();
for (String key : headersArray) {
String lowerKey = com.aliyun.darabonbastring.Client.toLower(key);
String value = headers.get(key);
if (!com.aliyun.teautil.Common.isUnset(value)) {
com.aliyun.darabonba.array.Client.append(newHeadersArray, lowerKey);
}

}
java.util.List<String> sortedHeadersArray = com.aliyun.darabonba.array.Client.ascSort(newHeadersArray);
String tmp = "";
String separator = "";
for (String key : sortedHeadersArray) {
String lowerKey = com.aliyun.darabonbastring.Client.toLower(key);
if (com.aliyun.darabonbastring.Client.hasPrefix(lowerKey, "x-acs-") || com.aliyun.darabonbastring.Client.equals(lowerKey, "host") || com.aliyun.darabonbastring.Client.equals(lowerKey, "content-type")) {
String value = headers.get(key);
if (!com.aliyun.teautil.Common.isUnset(value) && !com.aliyun.darabonbastring.Client.contains(tmp, lowerKey)) {
tmp = "" + tmp + "" + separator + "" + lowerKey + "";
if (com.aliyun.darabonbastring.Client.hasPrefix(key, "x-acs-") || com.aliyun.darabonbastring.Client.equals(key, "host") || com.aliyun.darabonbastring.Client.equals(key, "content-type")) {
if (!com.aliyun.darabonbastring.Client.contains(tmp, key)) {
tmp = "" + tmp + "" + separator + "" + key + "";
separator = ";";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.aliyun.gateway.pop;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -27,4 +31,60 @@ public void getRegionTest() throws Exception {
Assert.assertEquals("cn-hangzhou-acdr-ut-1", client.getRegion("test", "test-inner.cn-hangzhou-acdr-ut-1.aliyuncs.com", null));
Assert.assertEquals("cn-edge-1", client.getRegion("test", "test-inner.cn-edge-1.aliyuncs.com", null));
}

@Test
public void getSignedHeadersTest() throws Exception {
Client client = new Client();

// 测试空headers
Map<String, String> emptyHeaders = new HashMap<>();
List<String> result = client.getSignedHeaders(emptyHeaders);
Assert.assertEquals(1, result.size());

// 测试只包含需要签名的headers
Map<String, String> headers = new HashMap<>();
headers.put("host", "example.com");
headers.put("Host", "example.com");
headers.put("content-type", "application/json");
headers.put("x-acs-action", "TestAction");
result = client.getSignedHeaders(headers);
Assert.assertEquals(3, result.size());
Assert.assertEquals("content-type", result.get(0));
Assert.assertEquals("host", result.get(1));
Assert.assertEquals("x-acs-action", result.get(2));

// 测试包含不需要签名的headers
Map<String, String> headersWithIgnore = new HashMap<>();
headersWithIgnore.put("host", "example.com");
headersWithIgnore.put("content-type", "application/json");
headersWithIgnore.put("x-acs-action", "TestAction");
headersWithIgnore.put("authorization", "Bearer token");
headersWithIgnore.put("user-agent", "Java-client");
result = client.getSignedHeaders(headersWithIgnore);
Assert.assertEquals(3, result.size());
Assert.assertEquals("content-type", result.get(0));
Assert.assertEquals("host", result.get(1));
Assert.assertEquals("x-acs-action", result.get(2));

// 测试空值header
Map<String, String> headersWithEmpty = new HashMap<>();
headersWithEmpty.put("host", "example.com");
headersWithEmpty.put("content-type", null);
headersWithEmpty.put("x-acs-action", "TestAction");
result = client.getSignedHeaders(headersWithEmpty);
Assert.assertEquals(2, result.size());
Assert.assertEquals("host", result.get(0));
Assert.assertEquals("x-acs-action", result.get(1));

// 测试大小写不敏感
Map<String, String> headersWithCase = new HashMap<>();
headersWithCase.put("HOST", "example.com");
headersWithCase.put("Content-Type", "application/json");
headersWithCase.put("X-Acs-Action", "TestAction");
result = client.getSignedHeaders(headersWithCase);
Assert.assertEquals(3, result.size());
Assert.assertEquals("content-type", result.get(0));
Assert.assertEquals("host", result.get(1));
Assert.assertEquals("x-acs-action", result.get(2));
}
}
20 changes: 13 additions & 7 deletions alibabacloud-gateway-pop/main.tea
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,22 @@ function buildCanonicalizedHeaders(headers: map[string]string): string {

function getSignedHeaders(headers: map[string]string): [string] {
var headersArray : [string] = Map.keySet(headers);
var sortedHeadersArray = Array.ascSort(headersArray);
var newHeadersArray : [string] = [];
for(var key : headersArray) {
var lowerKey = String.toLower(key);
var value = headers[key];
if (!Util.isUnset(value)) {
Array.append(newHeadersArray, lowerKey);
}
}
var sortedHeadersArray = Array.ascSort(newHeadersArray);
var tmp : string = '';
var separator : string = '';
for(var key : sortedHeadersArray) {
var lowerKey = String.toLower(key);
if (String.hasPrefix(lowerKey, 'x-acs-') || String.equals(lowerKey, 'host')
|| String.equals(lowerKey, 'content-type')) {
var value = headers[key];
if (!Util.isUnset(value) && !String.contains(tmp, lowerKey)) {
tmp = `${tmp}${separator}${lowerKey}`;
if (String.hasPrefix(key, 'x-acs-') || String.equals(key, 'host')
|| String.equals(key, 'content-type')) {
if (!String.contains(tmp, key)) {
tmp = `${tmp}${separator}${key}`;
separator = ';';
}
}
Expand Down
18 changes: 12 additions & 6 deletions alibabacloud-gateway-pop/php/src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,21 @@ public function buildCanonicalizedHeaders($headers)
public function getSignedHeaders($headers)
{
$headersArray = MapUtil::keySet($headers);
$sortedHeadersArray = ArrayUtil::ascSort($headersArray);
$newHeadersArray = [];
foreach ($headersArray as $key) {
$lowerKey = StringUtil::toLower($key);
$value = @$headers[$key];
if (!Utils::isUnset($value)) {
ArrayUtil::append($newHeadersArray, $lowerKey);
}
}
$sortedHeadersArray = ArrayUtil::ascSort($newHeadersArray);
$tmp = "";
$separator = "";
foreach ($sortedHeadersArray as $key) {
$lowerKey = StringUtil::toLower($key);
if (StringUtil::hasPrefix($lowerKey, "x-acs-") || StringUtil::equals($lowerKey, "host") || StringUtil::equals($lowerKey, "content-type")) {
$value = @$headers[$key];
if (!Utils::isUnset($value) && !StringUtil::contains($tmp, $lowerKey)) {
$tmp = "" . $tmp . "" . $separator . "" . $lowerKey . "";
if (StringUtil::hasPrefix($key, "x-acs-") || StringUtil::equals($key, "host") || StringUtil::equals($key, "content-type")) {
if (!StringUtil::contains($tmp, $key)) {
$tmp = "" . $tmp . "" . $separator . "" . $key . "";
$separator = ";";
}
}
Expand Down
Loading
Loading