Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed May 11, 2024
2 parents dece3b5 + f092037 commit fa008ad
Show file tree
Hide file tree
Showing 123 changed files with 1,743 additions and 936 deletions.
18 changes: 15 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
# v4.4.500
# v4.4.506
### Client
* Update: Android: Show Notification & QuickLaunch Request after connect
* Update: Display AD without VPN
* Fix: Android: Crash when starting as always-on, but there is no selected server
* Fix: Android: importing access key by file
* Fix: minor issue in disconnect messages
* Deprecate: ServerProtocol Version 2 (451) is deprecated and no longer supported

### Server
* Update: Support Flexible Ad

# v4.4.500
### Client
* Update: Retry failed connection if the access token is updated from the server token URL
* Update: Move VpnHood Public Servers to VpnHood Connect App
* Fix: Ad service
* Fix: Sometimes the connect button didn't disconnect the current connection
* Fix: Android: Crash on disconnect
* Fix: Android: Fix Diagnoser mistakenly shows "Connection is not stable"
* Fix: Android: Fix Google Play Update
* Fix: Android: Diagnoser mistakenly shows "Connection is not stable"
* Fix: Android: Google Play Update
* Update: Android: Improve Android TV

### Server
Expand Down
4 changes: 2 additions & 2 deletions Pub/PubVersion.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": "4.4.500",
"BumpTime": "2024-04-30T21:06:07.1033614Z",
"Version": "4.4.506",
"BumpTime": "2024-05-11T09:07:36.0577031Z",
"Prerelease": false,
"DeprecatedVersion": "4.0.00"
}
12 changes: 7 additions & 5 deletions Tests/VpnHood.Test/TestDevice.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
using VpnHood.Client.Device;
using VpnHood.Client.App.Abstractions;
using VpnHood.Client.Device;

namespace VpnHood.Test;

internal class TestDevice(TestDeviceOptions? options = default) : IDevice
{
private readonly TestDeviceOptions _options = options ?? new TestDeviceOptions();

#pragma warning disable 0067
#pragma warning disable CS0067 // The event 'TestDevice.StartedAsService' is never used
public event EventHandler? StartedAsService;
#pragma warning restore 0067
public ICultureService? CultureService => null;
#pragma warning restore CS0067 // The event 'TestDevice.StartedAsService' is never used
public IAppCultureService? CultureService => null;
public string OsInfo => Environment.OSVersion + ", " + (Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit");
public bool IsExcludeAppsSupported => false;
public bool IsIncludeAppsSupported => false;
public bool IsLogToConsoleSupported => true;
public bool IsAlwaysOnSupported => false;

public DeviceAppInfo[] InstalledApps => throw new NotSupportedException();

public Task<IPacketCapture> CreatePacketCapture()
public Task<IPacketCapture> CreatePacketCapture(IUiContext? uiContext)
{
var res = new TestPacketCapture(_options);
return Task.FromResult((IPacketCapture)res);
Expand Down
12 changes: 8 additions & 4 deletions Tests/VpnHood.Test/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VpnHood.Client;
using VpnHood.Client.App;
using VpnHood.Client.App.Abstractions;
using VpnHood.Client.Device;
using VpnHood.Client.Diagnosing;
using VpnHood.Common;
Expand All @@ -24,8 +25,10 @@

namespace VpnHood.Test;


internal static class TestHelper
{
public class TestAppUiContext : IUiContext;
public static TestWebServer WebServer { get; private set; } = default!;
public static TestNetFilter NetFilter { get; private set; } = default!;

Expand Down Expand Up @@ -287,7 +290,7 @@ public static IDevice CreateDevice(TestDeviceOptions? options = default)

public static IPacketCapture CreatePacketCapture(TestDeviceOptions? options = default)
{
return CreateDevice(options).CreatePacketCapture().Result;
return CreateDevice(options).CreatePacketCapture(null).Result;
}

public static ClientOptions CreateClientOptions(bool useUdp = false)
Expand All @@ -312,7 +315,7 @@ public static async Task<VpnHoodClient> CreateClient(Token token,
clientOptions ??= CreateClientOptions();
if (clientOptions.ConnectTimeout == new ClientOptions().ConnectTimeout) clientOptions.ConnectTimeout = TimeSpan.FromSeconds(3);
clientOptions.PacketCaptureIncludeIpRanges = TestIpAddresses.Select(x => new IpRange(x)).ToArray();
clientOptions.ExcludeLocalNetwork = false;
clientOptions.IncludeLocalNetwork = true;

var client = new VpnHoodClient(
packetCapture,
Expand Down Expand Up @@ -350,7 +353,7 @@ public static VpnHoodConnect CreateClientConnect(Token token,
clientOptions.SessionTimeout = TimeSpan.FromSeconds(2); //overwrite default timeout
clientOptions.SocketFactory = new SocketFactory();
clientOptions.PacketCaptureIncludeIpRanges = TestIpAddresses.Select(x => new IpRange(x)).ToArray();
clientOptions.ExcludeLocalNetwork = false;
clientOptions.IncludeLocalNetwork = true;

var clientConnect = new VpnHoodConnect(
packetCapture,
Expand All @@ -370,7 +373,7 @@ public static AppOptions CreateClientAppOptions()
{
var appOptions = new AppOptions
{
AppDataFolderPath = Path.Combine(WorkingPath, "AppData_" + Guid.NewGuid()),
StorageFolderPath = Path.Combine(WorkingPath, "AppData_" + Guid.NewGuid()),
SessionTimeout = TimeSpan.FromSeconds(2),
LoadCountryIpGroups = false
};
Expand All @@ -390,6 +393,7 @@ public static VpnHoodApp CreateClientApp(TestDeviceOptions? deviceOptions = defa
clientApp.TcpTimeout = TimeSpan.FromSeconds(2);
clientApp.UserSettings.Logging.LogAnonymous = false;
clientApp.UserSettings.Logging.LogVerbose = true;
clientApp.UiContext = new TestAppUiContext();

return clientApp;
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/VpnHood.Test/Tests/AccessTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace VpnHood.Test.Tests;
public class AccessTest : TestBase
{
[TestMethod]
public Task Foo()
public async Task Foo()
{
return Task.Delay(0);
await Task.Delay(0);
}

[TestMethod]
Expand Down
92 changes: 75 additions & 17 deletions Tests/VpnHood.Test/Tests/AdTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VpnHood.Client.App;
using VpnHood.Client.App.Abstractions;
using VpnHood.Client.App.Exceptions;
using VpnHood.Client.Device;
using VpnHood.Client.Exceptions;
using VpnHood.Common.Collections;
using VpnHood.Common.Messaging;
using VpnHood.Common.Utils;
using VpnHood.Server.Access.Managers.File;

Expand All @@ -13,12 +15,16 @@ public class AdTest : TestBase
{
private class TestAdService(AdAccessManager accessManager) : IAppAdService
{
public bool FailAlways { get; set; }
public bool FailShow { get; set; }
public bool FailLoad { get; set; }

public Task ShowAd(string customData, CancellationToken cancellationToken)
public Task ShowAd(IUiContext uiContext, string customData, CancellationToken cancellationToken)
{
if (FailAlways)
throw new Exception("Ad failed");
if (FailLoad)
throw new AdLoadException("Load Ad failed.");

if (FailShow)
throw new Exception("Ad failed.");

accessManager.AddAdData(customData);
return Task.CompletedTask;
Expand Down Expand Up @@ -48,6 +54,57 @@ protected override bool IsValidAd(string? adData)
}
}

[TestMethod]
public async Task flexible_ad_should_not_close_session_if_load_ad_failed()
{
// create server
using var fileAccessManager = new AdAccessManager(TestHelper.CreateAccessManagerWorkingDir(),
TestHelper.CreateFileAccessManagerOptions());
using var testAccessManager = new TestAccessManager(fileAccessManager);
await using var server = TestHelper.CreateServer(testAccessManager);

// create access item
var accessItem = fileAccessManager.AccessItem_Create(adShow: AdShow.Flexible);
accessItem.Token.ToAccessKey();

// create client app
var appOptions = TestHelper.CreateClientAppOptions();
var adService = new TestAdService(fileAccessManager);
appOptions.AdService = adService;
await using var app = TestHelper.CreateClientApp(appOptions: appOptions);
adService.FailLoad = true;

// connect
var clientProfile = app.ClientProfileService.ImportAccessKey(accessItem.Token.ToAccessKey());
await app.Connect(clientProfile.ClientProfileId);
}

[TestMethod]
public async Task flexible_ad_should_close_session_if_display_ad_failed()
{
// create server
using var fileAccessManager = new AdAccessManager(TestHelper.CreateAccessManagerWorkingDir(),
TestHelper.CreateFileAccessManagerOptions());
using var testAccessManager = new TestAccessManager(fileAccessManager);
await using var server = TestHelper.CreateServer(testAccessManager);

// create access item
var accessItem = fileAccessManager.AccessItem_Create(adShow: AdShow.Flexible);
accessItem.Token.ToAccessKey();

// create client app
var appOptions = TestHelper.CreateClientAppOptions();
var adService = new TestAdService(fileAccessManager);
appOptions.AdService = adService;
await using var app = TestHelper.CreateClientApp(appOptions: appOptions);
adService.FailShow = true;

// connect
var clientProfile = app.ClientProfileService.ImportAccessKey(accessItem.Token.ToAccessKey());
await Assert.ThrowsExceptionAsync<AdException>(() => app.Connect(clientProfile.ClientProfileId));
await TestHelper.WaitForClientStateAsync(app, AppConnectionState.None);
}

[TestMethod]
public async Task Session_must_be_closed_after_few_minutes_if_ad_is_not_accepted()
{
Expand All @@ -58,14 +115,15 @@ public async Task Session_must_be_closed_after_few_minutes_if_ad_is_not_accepted
await using var server = TestHelper.CreateServer(testAccessManager);

// create access item
var accessItem = fileAccessManager.AccessItem_Create(isAdRequired: true);
var accessItem = fileAccessManager.AccessItem_Create(adShow: AdShow.Required);
accessItem.Token.ToAccessKey();

// create client app
await using var app = TestHelper.CreateClientApp();
var appOptions = TestHelper.CreateClientAppOptions();
var adService = new TestAdService(fileAccessManager);
adService.FailAlways = true;
app.Services.AdService = adService;
appOptions.AdService = adService;
await using var app = TestHelper.CreateClientApp(appOptions: appOptions);
adService.FailShow = true;

// connect
var clientProfile = app.ClientProfileService.ImportAccessKey(accessItem.Token.ToAccessKey());
Expand All @@ -83,13 +141,13 @@ public async Task Session_expiration_must_increase_by_ad()
await using var server = TestHelper.CreateServer(testAccessManager);

// create access item
var accessItem = fileAccessManager.AccessItem_Create(isAdRequired: true);
var accessItem = fileAccessManager.AccessItem_Create(adShow: AdShow.Required);
accessItem.Token.ToAccessKey();

// create client app
await using var app = TestHelper.CreateClientApp();
var adService = new TestAdService(fileAccessManager);
app.Services.AdService = adService;
var appOptions = TestHelper.CreateClientAppOptions();
appOptions.AdService = new TestAdService(fileAccessManager);
await using var app = TestHelper.CreateClientApp(appOptions: appOptions);

// connect
var clientProfile = app.ClientProfileService.ImportAccessKey(accessItem.Token.ToAccessKey());
Expand All @@ -109,14 +167,14 @@ public async Task Session_exception_should_be_short_if_ad_is_not_accepted()
await using var server = TestHelper.CreateServer(testAccessManager);

// create access item
var accessItem = fileAccessManager.AccessItem_Create(isAdRequired: true);
var accessItem = fileAccessManager.AccessItem_Create(adShow: AdShow.Required);
accessItem.Token.ToAccessKey();
fileAccessManager.RejectAllAds = true; // server will reject all ads

// create client app
await using var app = TestHelper.CreateClientApp();
var adService = new TestAdService(fileAccessManager);
app.Services.AdService = adService;
var appOptions = TestHelper.CreateClientAppOptions();
appOptions.AdService = new TestAdService(fileAccessManager);
await using var app = TestHelper.CreateClientApp(appOptions: appOptions);

// connect
var clientProfile = app.ClientProfileService.ImportAccessKey(accessItem.Token.ToAccessKey());
Expand Down
4 changes: 2 additions & 2 deletions Tests/VpnHood.Test/Tests/ClientAppTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public async Task ClientProfiles_CRUD()
// ************
// *** TEST ***: AddAccessKey should add a clientProfile
var token1 = CreateToken();
token1.ServerToken.Regions = [new HostRegion{RegionId = "r1"}, new HostRegion { RegionId = "r2" }];
token1.ServerToken.Regions = [new HostRegion{RegionId = "r1", CountryCode = "US"}, new HostRegion { RegionId = "r2", CountryCode = "US" }];
var clientProfile1 = app.ClientProfileService.ImportAccessKey(token1.ToAccessKey());
Assert.IsNotNull(app.ClientProfileService.FindByTokenId(token1.TokenId), "ClientProfile is not added");
Assert.AreEqual(token1.TokenId, clientProfile1.Token.TokenId, "invalid tokenId has been assigned to clientProfile");
Expand Down Expand Up @@ -177,7 +177,7 @@ public async Task Save_load_clientProfiles()
await app.DisposeAsync();

var appOptions = TestHelper.CreateClientAppOptions();
appOptions.AppDataFolderPath = app.AppDataFolderPath;
appOptions.StorageFolderPath = app.StorageFolderPath;

await using var app2 = TestHelper.CreateClientApp(appOptions: appOptions);
Assert.AreEqual(clientProfiles.Length, app2.ClientProfileService.List().Length, "ClientProfiles count are not same!");
Expand Down
Loading

0 comments on commit fa008ad

Please sign in to comment.