Add authentication support for protected file downloads (Issue #22)#73
Conversation
…i#22) Implement ability to download files that require authentication: - Basic Auth (username/password) - Bearer Token (OAuth-style) - Cookie-based authentication - Custom HTTP headers Changes: - Add AuthenticationType enum with 5 auth modes - Add 6 auth properties to FileDownloadQueueItem model - Create HttpRequestAuthenticator helper for applying auth - Update DownloadQueueService to apply auth at 5 HTTP request points - Add Authentication Settings UI to DownloadFromDirectLink page - Add 19 unit tests for HttpRequestAuthenticator - Include EF Core migration for new database columns Tested with httpbin.org authentication endpoints.
Summary of ChangesHello @thromel, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the file download functionality by enabling support for protected files. It introduces a robust system for handling various authentication types, ensuring that the application can securely access resources that require credentials, tokens, or custom headers. The changes span data modeling, core download logic, a new authentication helper, and user interface elements, providing a complete solution for authenticated downloads. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive authentication mechanism for file downloads, supporting Basic Auth, Bearer Tokens, Cookies, and Custom Headers. The implementation is well-structured, with a dedicated HttpRequestAuthenticator helper, corresponding model changes, and UI components for configuration. The changes are thoroughly tested with 19 new unit tests covering various authentication scenarios and edge cases. The authentication logic is correctly integrated into all relevant parts of the download process, including initial requests, retries, and parallel chunk downloads.
My review focuses on a minor refactoring opportunity in the new unit tests to improve conciseness and maintainability. Overall, this is a high-quality contribution that significantly enhances the application's capabilities.
| [Fact] | ||
| public void HasAuthentication_ReturnsTrue_WhenAuthTypeIsNotNone() | ||
| { | ||
| // Arrange | ||
| var queueItem = new FileDownloadQueueItem | ||
| { | ||
| AuthType = AuthenticationType.BasicAuth | ||
| }; | ||
|
|
||
| // Assert | ||
| Assert.True(queueItem.HasAuthentication); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void HasAuthentication_ReturnsFalse_WhenAuthTypeIsNone() | ||
| { | ||
| // Arrange | ||
| var queueItem = new FileDownloadQueueItem | ||
| { | ||
| AuthType = AuthenticationType.None | ||
| }; | ||
|
|
||
| // Assert | ||
| Assert.False(queueItem.HasAuthentication); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(AuthenticationType.BasicAuth)] | ||
| [InlineData(AuthenticationType.BearerToken)] | ||
| [InlineData(AuthenticationType.Cookie)] | ||
| [InlineData(AuthenticationType.CustomHeaders)] | ||
| public void HasAuthentication_ReturnsTrue_ForAllAuthTypes(AuthenticationType authType) | ||
| { | ||
| // Arrange | ||
| var queueItem = new FileDownloadQueueItem | ||
| { | ||
| AuthType = authType | ||
| }; | ||
|
|
||
| // Assert | ||
| Assert.True(queueItem.HasAuthentication); | ||
| } |
There was a problem hiding this comment.
These three tests for the HasAuthentication property can be consolidated into a single, more concise [Theory] test. This improves readability and maintainability by reducing code duplication and covering all cases in one place.
[Theory]
[InlineData(AuthenticationType.BasicAuth, true)]
[InlineData(AuthenticationType.BearerToken, true)]
[InlineData(AuthenticationType.Cookie, true)]
[InlineData(AuthenticationType.CustomHeaders, true)]
[InlineData(AuthenticationType.None, false)]
public void HasAuthentication_ReturnsCorrectValue_ForAuthType(AuthenticationType authType, bool expected)
{
// Arrange
var queueItem = new FileDownloadQueueItem
{
AuthType = authType
};
// Assert
Assert.Equal(expected, queueItem.HasAuthentication);
}- Update Microsoft.AspNetCore.Identity.EntityFrameworkCore from 8.0.22 to 8.0.23 - Remove duplicate Microsoft.EntityFrameworkCore.InMemory reference
Address Gemini code review feedback: combine three separate tests into one parameterized Theory test for improved conciseness.
Summary
Implements Issue #22: Add Ability to Download Password/Cookie Protected Files
This feature enables downloading files that require authentication by supporting multiple authentication methods.
Authentication Types Supported
Changes
New Files
Models/AuthenticationType.csHelpers/HttpRequestAuthenticator.csTests/Services/HttpRequestAuthenticatorTests.csMigrations/AddDownloadAuthentication.csModified Files
Models/FileDownloadQueueItem.csServices/DownloadQueueService.csComponents/Download/DownloadFromDirectLink.razorImplementation Details
Data Model
Added to
FileDownloadQueueItem:AuthType- Enum specifying auth methodAuthUsername/AuthPassword- For Basic AuthAuthBearerToken- For Bearer tokensAuthCookies- For cookie-based authAuthCustomHeaders- JSON string for custom headersHTTP Request Integration
Authentication is applied at 5 points in
DownloadQueueService:Test plan
Security Notes
InputType.Password)