Fix bug where we cannot use SAS authentication to move file/directory (#3422)
* Fix bug where we cannot use SAS authentication to move file/directory * CL * ut
This commit is contained in:
parent
c4678c9a10
commit
71bdfddfee
@ -8,6 +8,8 @@
|
||||
|
||||
### Bugs Fixed
|
||||
|
||||
- Fixed a bug where file/directory renaming cannot be authenticated with SAS.
|
||||
|
||||
### Other Changes
|
||||
|
||||
## 12.3.1 (2022-03-09)
|
||||
|
||||
@ -115,7 +115,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
|
||||
protocolLayerOptions.SourceIfNoneMatch = options.SourceAccessConditions.IfNoneMatch;
|
||||
protocolLayerOptions.SourceIfModifiedSince = options.SourceAccessConditions.IfModifiedSince;
|
||||
protocolLayerOptions.SourceIfUnmodifiedSince = options.SourceAccessConditions.IfUnmodifiedSince;
|
||||
protocolLayerOptions.RenameSource = "/" + sourceDfsUrl.GetPath();
|
||||
protocolLayerOptions.RenameSource = "/" + sourceDfsUrl.GetRelativeUrl();
|
||||
auto response = _detail::PathClient::Create(
|
||||
*m_pipeline, destinationDfsUrl, protocolLayerOptions, context);
|
||||
|
||||
@ -163,7 +163,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
|
||||
protocolLayerOptions.SourceIfNoneMatch = options.SourceAccessConditions.IfNoneMatch;
|
||||
protocolLayerOptions.SourceIfModifiedSince = options.SourceAccessConditions.IfModifiedSince;
|
||||
protocolLayerOptions.SourceIfUnmodifiedSince = options.SourceAccessConditions.IfUnmodifiedSince;
|
||||
protocolLayerOptions.RenameSource = "/" + sourceDfsUrl.GetPath();
|
||||
protocolLayerOptions.RenameSource = "/" + sourceDfsUrl.GetRelativeUrl();
|
||||
auto response = _detail::PathClient::Create(
|
||||
*m_pipeline, destinationDfsUrl, protocolLayerOptions, context);
|
||||
|
||||
|
||||
@ -352,7 +352,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
|
||||
protocolLayerOptions.SourceIfNoneMatch = options.SourceAccessConditions.IfNoneMatch;
|
||||
protocolLayerOptions.SourceIfModifiedSince = options.SourceAccessConditions.IfModifiedSince;
|
||||
protocolLayerOptions.SourceIfUnmodifiedSince = options.SourceAccessConditions.IfUnmodifiedSince;
|
||||
protocolLayerOptions.RenameSource = "/" + sourceDfsUrl.GetPath();
|
||||
protocolLayerOptions.RenameSource = "/" + sourceDfsUrl.GetRelativeUrl();
|
||||
auto result = _detail::PathClient::Create(
|
||||
*m_pipeline, destinationDfsUrl, protocolLayerOptions, context);
|
||||
|
||||
@ -400,7 +400,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
|
||||
protocolLayerOptions.SourceIfNoneMatch = options.SourceAccessConditions.IfNoneMatch;
|
||||
protocolLayerOptions.SourceIfModifiedSince = options.SourceAccessConditions.IfModifiedSince;
|
||||
protocolLayerOptions.SourceIfUnmodifiedSince = options.SourceAccessConditions.IfUnmodifiedSince;
|
||||
protocolLayerOptions.RenameSource = "/" + sourceDfsUrl.GetPath();
|
||||
protocolLayerOptions.RenameSource = "/" + sourceDfsUrl.GetRelativeUrl();
|
||||
auto result = _detail::PathClient::Create(
|
||||
*m_pipeline, destinationDfsUrl, protocolLayerOptions, context);
|
||||
|
||||
|
||||
@ -167,6 +167,36 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_THROW(newFileClient.GetProperties(), StorageException);
|
||||
}
|
||||
|
||||
TEST_F(DataLakeDirectoryClientTest, RenameFileSasAuthentication_LIVEONLY_)
|
||||
{
|
||||
const std::string testName(GetTestName());
|
||||
const std::string sourceFilename = testName + "1";
|
||||
const std::string destinationFilename = testName + "2";
|
||||
auto baseDirectoryClient = m_fileSystemClient->GetDirectoryClient("based");
|
||||
baseDirectoryClient.Create();
|
||||
auto fileClient = baseDirectoryClient.GetFileClient(sourceFilename);
|
||||
fileClient.CreateIfNotExists();
|
||||
|
||||
Files::DataLake::DataLakeDirectoryClient directoryClientSas(
|
||||
Files::DataLake::_detail::GetDfsUrlFromUrl(baseDirectoryClient.GetUrl()) + GetSas());
|
||||
directoryClientSas.RenameFile(sourceFilename, destinationFilename);
|
||||
EXPECT_THROW(
|
||||
baseDirectoryClient.GetFileClient(sourceFilename).GetProperties(), StorageException);
|
||||
EXPECT_NO_THROW(m_fileSystemClient->GetFileClient(destinationFilename).GetProperties());
|
||||
|
||||
const std::string sourceDirectoryName = testName + "3";
|
||||
const std::string destinationDirectoryName = testName + "4";
|
||||
auto directoryClient = baseDirectoryClient.GetSubdirectoryClient(sourceDirectoryName);
|
||||
directoryClient.CreateIfNotExists();
|
||||
|
||||
directoryClientSas.RenameSubdirectory(sourceDirectoryName, destinationDirectoryName);
|
||||
EXPECT_THROW(
|
||||
baseDirectoryClient.GetSubdirectoryClient(sourceDirectoryName).GetProperties(),
|
||||
StorageException);
|
||||
EXPECT_NO_THROW(
|
||||
m_fileSystemClient->GetDirectoryClient(destinationDirectoryName).GetProperties());
|
||||
}
|
||||
|
||||
TEST_F(DataLakeDirectoryClientTest, RenameFileAccessCondition)
|
||||
{
|
||||
const std::string testName(GetTestName());
|
||||
|
||||
@ -18,6 +18,18 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
|
||||
const size_t PathTestSize = 5;
|
||||
|
||||
std::string DataLakeFileSystemClientTest::GetSas()
|
||||
{
|
||||
Sas::DataLakeSasBuilder sasBuilder;
|
||||
sasBuilder.Protocol = Sas::SasProtocol::HttpsAndHttp;
|
||||
sasBuilder.ExpiresOn = std::chrono::system_clock::now() + std::chrono::hours(72);
|
||||
sasBuilder.FileSystemName = m_fileSystemName;
|
||||
sasBuilder.Resource = Sas::DataLakeSasResource::FileSystem;
|
||||
sasBuilder.SetPermissions(Sas::DataLakeFileSystemSasPermissions::All);
|
||||
return sasBuilder.GenerateSasToken(
|
||||
*_internal::ParseConnectionString(AdlsGen2ConnectionString()).KeyCredential);
|
||||
}
|
||||
|
||||
void DataLakeFileSystemClientTest::CreateDirectoryList()
|
||||
{
|
||||
std::string const directoryName(GetFileSystemValidName());
|
||||
@ -555,4 +567,32 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_THROW(newDirectoryClient.GetProperties(), StorageException);
|
||||
}
|
||||
|
||||
TEST_F(DataLakeFileSystemClientTest, RenameFileSasAuthentication_LIVEONLY_)
|
||||
{
|
||||
const std::string testName(GetTestName());
|
||||
const std::string sourceFilename = testName + "1";
|
||||
const std::string destinationFilename = testName + "2";
|
||||
auto fileClient = m_fileSystemClient->GetFileClient(sourceFilename);
|
||||
fileClient.CreateIfNotExists();
|
||||
|
||||
Files::DataLake::DataLakeFileSystemClient fileSystemClientSas(
|
||||
Files::DataLake::_detail::GetDfsUrlFromUrl(m_fileSystemClient->GetUrl()) + GetSas());
|
||||
fileSystemClientSas.RenameFile(sourceFilename, destinationFilename);
|
||||
EXPECT_THROW(
|
||||
m_fileSystemClient->GetFileClient(sourceFilename).GetProperties(), StorageException);
|
||||
EXPECT_NO_THROW(m_fileSystemClient->GetFileClient(destinationFilename).GetProperties());
|
||||
|
||||
const std::string sourceDirectoryName = testName + "3";
|
||||
const std::string destinationDirectoryName = testName + "4";
|
||||
auto directoryClient = m_fileSystemClient->GetDirectoryClient(sourceDirectoryName);
|
||||
directoryClient.CreateIfNotExists();
|
||||
|
||||
fileSystemClientSas.RenameDirectory(sourceDirectoryName, destinationDirectoryName);
|
||||
EXPECT_THROW(
|
||||
m_fileSystemClient->GetDirectoryClient(sourceDirectoryName).GetProperties(),
|
||||
StorageException);
|
||||
EXPECT_NO_THROW(
|
||||
m_fileSystemClient->GetDirectoryClient(destinationDirectoryName).GetProperties());
|
||||
}
|
||||
|
||||
}}} // namespace Azure::Storage::Test
|
||||
|
||||
@ -12,6 +12,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
protected:
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
std::string GetSas();
|
||||
void CreateDirectoryList();
|
||||
|
||||
std::vector<Files::DataLake::Models::PathItem> ListAllPaths(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user