Claus Ibsen created CAMEL-27726:
-----------------------------------
Summary: camel-azure-files: NPE on share root,
SHARED_KEY_CREDENTIAL unused, shared key with host URI
Key: CAMEL-27726
URL: https://issues.apache.org/jira/browse/CAMEL-27726
Project: Camel
Issue Type: Bug
Components: camel-azure
Reporter: Claus Ibsen
Fix For: 4.24.0
Found while improving the option descriptions of camel-azure-files for
CAMEL-23832 (commit
https://github.com/apache/camel/commit/0556838c63bc9f44b437c435d7fd2763ba5f3d75).
These are separate problems of the component; the descriptions commit only
documents the current behavior.
h4. 1. A consumer on the share root fails to build the file path
For an endpoint without a directory, such as
{{azure-files://myaccount/myshare}}, {{FilesConfiguration.setDirectory()}} sets
the directory to {{/}}. {{FilesConsumer.pollDirectory()}} trims it to an empty
path, so {{FilesPath.concat()}} gives the listed files a path without a leading
{{/}}, for example {{order.xml}} or {{2026/order.xml}}.
{{FilesConsumer.asRemoteFile()}} and {{getRelativeFilePath()}} then compute the
relative path with {{StringHelper.after(path, "/")}}. For a file at the share
root this returns null, and {{FilesPath.ensureRelative(null)}} throws a
NullPointerException. For a file in a subdirectory (recursive=true) it drops
the first directory, so {{2026/order.xml}} becomes {{order.xml}}. Also
{{FilesOperations.getDirClient("")}} fails its {{assert
FilesPath.isAbsolute(path)}} when assertions are on.
The first SAS example of the doc page uses such an endpoint.
Proposed change: keep the {{/}} of the share root when the consumer lists it,
or compute the relative path without {{StringHelper.after}}, and add a test
that consumes from the share root.
h4. 2. credentialType=SHARED_KEY_CREDENTIAL does nothing
{{FilesOperations.createClient()}} has branches for SHARED_ACCOUNT_KEY,
AZURE_SAS and AZURE_IDENTITY only. With SHARED_KEY_CREDENTIAL, which the option
lists in its enums, the client is built without credentials and every request
fails to authenticate. The same happens with the default SHARED_ACCOUNT_KEY
when {{sharedKey}} is not set: there is no error that says the key is missing.
Proposed change: remove SHARED_KEY_CREDENTIAL from the enums of
{{credentialType}} (or treat it as the shared key), and fail at endpoint
creation when the option that the chosen credentialType needs is not set.
h4. 3. The shared key fails with the host name form of the URI
For {{azure-files://myaccount.file.core.windows.net/myshare}}, the
{{FilesConfiguration(URI)}} constructor sets {{account}} to the whole host name
({{FilesConfigurationTest.accountForAccountHostURIShouldBeExtracted}} asserts
this). {{FilesOperations.createClient()}} passes {{configuration.getAccount()}}
to {{new StorageSharedKeyCredential(...)}}, which puts the account name in the
string it signs. The signature then names the account
{{myaccount.file.core.windows.net}}, and the file service rejects the requests.
SAS and Azure Identity are not affected.
Proposed change: use the part of the host before the first dot as the account
name, or pass the account name separately to the credential.
h4. 4. The SAS token is never checked
{{FilesToken.isInvalid()}} checks that sig, sv and se are set and that the
token is for the file service, but nothing calls it. A SAS token with a missing
part only fails at the first request, with an error from the file service.
Proposed change: call {{isInvalid()}} for credentialType=AZURE_SAS when the
client is created, and fail with a message that names the missing part, or
remove the method.
h4. 5. The port option does nothing, and three inherited option texts are about
FTP
{{FilesOperations.createClient()}} always builds the endpoint {{https://}} plus
the host, so the {{port}} path option is not used. Its text, inherited from
{{RemoteFileConfiguration}}, is "Port of the FTP server". The texts of
{{timeout}} ("Used only by FTPClient") and {{connectTimeout}} ("Used by both
FTPClient and JSCH") are inherited too: here {{timeout}} is the timeout of the
data and metadata requests ({{FilesEndpoint.getDataTimeout()}},
{{getMetadataTimeout()}}), and {{connectTimeout}} only the timeout of
{{forceCloseAllHandles}} in {{FilesOperations.forceDisconnect()}}.
Proposed change: exclude {{port}} from the endpoint (or use it), and give
{{timeout}} and {{connectTimeout}} texts that fit Azure Files.
h4. 6. The doc page describes the SAS token wrongly
{{azure-files-component.adoc}} says that the SAS token is given "through the
{{token}} parameter", but there is no such option: the parts of the token are
the options sv, ss, srt, sp, se, st, spr, sig and so on. Its first URI example
gives these parts without {{credentialType=AZURE_SAS}}, so with the default
SHARED_ACCOUNT_KEY the token is ignored and the requests carry no credentials.
Proposed change: name the SAS options in the text and add
{{credentialType=AZURE_SAS}} to the example.
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)