[ https://issues.apache.org/jira/browse/HADOOP-19352?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17925504#comment-17925504 ]
ASF GitHub Bot commented on HADOOP-19352: ----------------------------------------- drankye commented on code in PR #7205: URL: https://github.com/apache/hadoop/pull/7205#discussion_r1948550925 ########## hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/ITAliyunOSSSignatureV4.java: ########## @@ -0,0 +1,107 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.fs.aliyun.oss; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileAlreadyExistsException; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.FileSystemContractBaseTest; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.FSDataOutputStream; +import static org.apache.hadoop.fs.contract.ContractTestUtils.dataset; +import static org.apache.hadoop.fs.contract.ContractTestUtils.createFile; + +import org.apache.hadoop.security.UserGroupInformation; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assume.assumeFalse; +import static org.junit.Assume.assumeNotNull; +import static org.junit.Assume.assumeTrue; + +import static org.apache.hadoop.fs.aliyun.oss.Constants.SIGNATURE_VERSION_KEY; +import static org.apache.hadoop.fs.aliyun.oss.Constants.REGION_KEY; + +/** + * Tests Aliyun OSS system. + */ +public class ITAliyunOSSSignatureV4 { + private static final Logger LOG = LoggerFactory.getLogger(ITAliyunOSSSignatureV4.class); + private Configuration conf; + private URI testURI; + private Path testFile = new Path("ITAliyunOSSSignatureV4/atestr"); + + @Before + public void setUp() throws Exception { + conf = new Configuration(); + String bucketUri = conf.get("test.fs.oss.name"); + LOG.debug("bucketUri={}", bucketUri); + testURI = URI.create(bucketUri); + } + + @Test + public void testV4() throws IOException { + conf.set(SIGNATURE_VERSION_KEY, "V4"); + conf.set(REGION_KEY, "cn-hongkong"); + AliyunOSSFileSystem fs = new AliyunOSSFileSystem(); + fs.initialize(testURI, conf); + assumeNotNull(fs); + + createFile(fs, testFile, true, dataset(256, 0, 255)); + FileStatus status = fs.getFileStatus(testFile); + fs.delete(testFile); + fs.close(); + } + + @Test + public void testDefaultSignatureVersion() throws IOException { + AliyunOSSFileSystem fs = new AliyunOSSFileSystem(); + fs.initialize(testURI, conf); + assumeNotNull(fs); + + Path testFile = new Path("/test/atestr"); + createFile(fs, testFile, true, dataset(256, 0, 255)); + FileStatus status = fs.getFileStatus(testFile); + fs.delete(testFile); + fs.close(); + } + + @Test + public void testV4WithoutRegion() throws IOException { Review Comment: The test should check and fail when the desired exception isn't thrown. ########## hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystemStore.java: ########## @@ -113,6 +114,16 @@ public void initialize(URI uri, Configuration conf, String user, conf.get(USER_AGENT_PREFIX, USER_AGENT_PREFIX_DEFAULT) + ", Hadoop/" + VersionInfo.getVersion()); + String region = conf.get(REGION_KEY, ""); + String signatureVersion = conf.get(SIGNATURE_VERSION_KEY, SIGNATURE_VERSION_DEFAULT); + if ("V4".equalsIgnoreCase(signatureVersion)) { + clientConf.setSignatureVersion(SignVersion.V4); + if (StringUtils.isEmpty(region)) { + LOG.error("Signature version is V4 ,but region is empty."); + throw new IllegalArgumentException("SignVersion is V4 but region is empty"); Review Comment: Please double check if it's more appropriate to throw IOException instead. > Hadoop OSS Connector adds support for V4 signatures. > ---------------------------------------------------- > > Key: HADOOP-19352 > URL: https://issues.apache.org/jira/browse/HADOOP-19352 > Project: Hadoop Common > Issue Type: Improvement > Components: fs/oss > Reporter: zhouao > Assignee: zhouao > Priority: Major > Labels: pull-request-available > > AliyunOSS is about to adjust its security policy: only V4 signature requests > will be supported in the public cloud. Therefore, support for V4 signatures > is also required in Hadoop, and V4 signatures will be the default. -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org