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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ tests/obj/
.worktrees/
*.user
*.suo
*.plgx
*.dll
9 changes: 1 addition & 8 deletions src/PluginPathResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ namespace KeePassAutoReload
{
internal enum PluginPackageFormat
{
Dll,
Plgx
Dll
}

internal static class PluginPathResolver
Expand Down Expand Up @@ -36,14 +35,8 @@ public static PluginPackageFormat ResolveInstalledFormat(string keepassExecutabl
}

string pluginsDir = Path.Combine(keepassExecutableDirectory, "Plugins");
string plgxPath = Path.Combine(pluginsDir, "KeePassAutoReload.plgx");
string dllPath = Path.Combine(pluginsDir, "KeePassAutoReload.dll");

if (File.Exists(plgxPath))
{
return PluginPackageFormat.Plgx;
}

return File.Exists(dllPath) ? PluginPackageFormat.Dll : PluginPackageFormat.Dll;
}
Comment on lines 40 to 41

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logical Redundancy in Return Statement

The return statement in ResolveInstalledFormat uses a ternary operator to return PluginPackageFormat.Dll regardless of whether the file exists:

return File.Exists(dllPath) ? PluginPackageFormat.Dll : PluginPackageFormat.Dll;

This is redundant and does not provide any meaningful distinction between the two cases. Consider handling the scenario where the DLL does not exist, either by throwing an exception, returning a different format, or logging an error for better maintainability and clarity.

}
Expand Down
3 changes: 1 addition & 2 deletions src/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ private static bool TryParseVersion(string value, out Version version)
private static string BuildAssetUrl(string tagName, PluginPackageFormat format)
{
if (string.IsNullOrEmpty(tagName)) return ReleasesUrl;
string extension = format == PluginPackageFormat.Plgx ? ".plgx" : ".dll";
return "https://github.com/hieuck/KeePassAutoReload/releases/download/" + tagName + "/KeePassAutoReload" + extension;
return "https://github.com/hieuck/KeePassAutoReload/releases/download/" + tagName + "/KeePassAutoReload.dll";
}
Comment on lines 171 to 175

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic Issue:
The BuildAssetUrl method accepts a format parameter but does not use it, always returning the DLL asset URL. If multiple asset formats are supported, the method should use the format parameter to construct the correct URL. Otherwise, remove the parameter to avoid confusion.

Recommended Solution:
Update the method to handle different formats, e.g.:

switch (format) {
    case PluginPackageFormat.Dll:
        return $"https://github.com/hieuck/KeePassAutoReload/releases/download/{tagName}/KeePassAutoReload.dll";
    // Add cases for other formats
    default:
        throw new ArgumentException("Unsupported format", nameof(format));
}


private static string BuildReleaseUrl(string tagName)
Comment on lines 171 to 177

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security/Consistency Issue:
Neither BuildAssetUrl nor BuildReleaseUrl validate or sanitize the tagName input. If tagName is derived from external sources, this could lead to malformed URLs or potential injection vulnerabilities.

Recommended Solution:
Sanitize tagName to ensure it contains only valid characters for a URL path segment before using it in URL construction.

Expand Down
28 changes: 0 additions & 28 deletions tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,6 @@ public async Task ReturnsDllAssetUrlByDefault()
Assert.EndsWith("KeePassAutoReload.dll", info.AssetUrl);
}

[Fact]
public async Task ReturnsPlgxAssetUrlWhenFormatIsPlgx()
{
FakeUpdateClient client = new FakeUpdateClient { Response = "[{\"tag_name\":\"v1.0.1\"}]" };
UpdateInfo info = await UpdateChecker.CheckLatestAsync(client, PluginPackageFormat.Plgx);
Assert.EndsWith("KeePassAutoReload.plgx", info.AssetUrl);
}

[Fact]
public async Task ThrowsOperationCanceledExceptionWhenAlreadyCanceled()
{
Expand Down Expand Up @@ -302,26 +294,6 @@ public void ThrowsWhenKeePassDirectoryIsNullOrWhitespace(string keepassDirectory
Assert.Throws<ArgumentException>(() => PluginPathResolver.ResolvePluginPackagePath(null, keepassDirectory));
}

[Fact]
public void ResolveInstalledFormat_DetectsPlgxWhenPlgxFileExists()
{
string tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
try
{
string pluginsDir = Path.Combine(tempDir, "Plugins");
Directory.CreateDirectory(pluginsDir);
File.WriteAllText(Path.Combine(pluginsDir, "KeePassAutoReload.plgx"), "plgx");
File.WriteAllText(Path.Combine(pluginsDir, "KeePassAutoReload.dll"), "dll");

PluginPackageFormat format = PluginPathResolver.ResolveInstalledFormat(tempDir);
Assert.Equal(PluginPackageFormat.Plgx, format);
}
finally
{
if (Directory.Exists(tempDir)) Directory.Delete(tempDir, true);
}
}

[Fact]
public void ResolveInstalledFormat_DefaultsToDllWhenOnlyDllExists()
{
Expand Down