Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addresses issue #8, allowing "." as a separator inside a relay name #93

Merged
merged 1 commit into from
Aug 29, 2024
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: 1 addition & 0 deletions Microsoft.Azure.Relay.Bridge.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
global.json = global.json
LICENSE.txt = LICENSE.txt
NuGetPackageVerifier.json = NuGetPackageVerifier.json
OVERVIEW.md = OVERVIEW.md
package-all.cmd = package-all.cmd
package.cmd = package.cmd
package.sh = package.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public string RelayName
{
var val = value != null ? value.Trim('\'', '\"') : value;
if (val != null &&
!new Regex("^[0-9A-Za-z_-]+$").Match(val).Success)
!Constants.RelayNameRegex.Match(val).Success)
{
throw BridgeEventSource.Log.ArgumentOutOfRange(
nameof(RelayName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public string PortName
{
var val = value != null ? value.Trim('\'', '\"') : value;
if (val != null &&
!new Regex("^[0-9A-Za-z_-]+$").Match(val).Success)
!Constants.RelayNameRegex.Match(val).Success)
{
throw BridgeEventSource.Log.ArgumentOutOfRange(
nameof(PortName),
Expand All @@ -180,7 +180,7 @@ public string BindLocalSocket
Uri path;
if (val != null &&
!Uri.TryCreate(val, UriKind.Absolute, out path) &&
!new Regex("^[0-9A-Za-z_-]+$").Match(val).Success)
!Constants.RelayNameRegex.Match(val).Success)
{
throw BridgeEventSource.Log.ArgumentOutOfRange(
nameof(BindLocalSocket),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public string RelayName
{
var val = value != null ? value.Trim('\'', '\"') : value;
if (val != null &&
!new Regex("^[0-9A-Za-z/_-]+$").Match(val).Success)
!Constants.RelayNameRegex.Match(val).Success)
{
throw BridgeEventSource.Log.ArgumentOutOfRange(
nameof(RelayName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public string PortName
{
var val = value != null ? value.Trim('\'', '\"') : value;
if (val != null &&
!new Regex("^[0-9A-Za-z_-]+$").Match(val).Success)
!Constants.RelayNameRegex.Match(val).Success)
{
throw BridgeEventSource.Log.ArgumentOutOfRange(
nameof(PortName),
Expand All @@ -86,7 +86,7 @@ public string LocalSocket
Uri path;
if (val != null &&
!Uri.TryCreate(val, UriKind.Absolute, out path) &&
!new Regex("^[0-9A-Za-z_-]+$").Match(val).Success)
!Constants.RelayNameRegex.Match(val).Success)
{
throw BridgeEventSource.Log.ArgumentOutOfRange(
nameof(LocalSocket),
Expand Down
6 changes: 4 additions & 2 deletions src/Microsoft.Azure.Relay.Bridge/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Text.RegularExpressions;

namespace Microsoft.Azure.Relay.Bridge
{
static class Constants
public static class Constants
{

public static Regex RelayNameRegex = new Regex(@"^[0-9A-Za-z/_\-\.]+$", RegexOptions.Compiled);
}
}
50 changes: 50 additions & 0 deletions test/unit/Microsoft.Azure.Relay.Bridge.Tests/ConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,56 @@ public void CommandLineBadLocalForwardTest()
Assert.Contains("BindAddress", ex2.Message);
}

[Fact]
public void CommandLineGoodRemoteForwardTest()
{
CommandLineSettings.Run(new string[] { "-R", "foobar:3000" },
(settings) =>
{
var cfg = Config.LoadConfig(settings);
Assert.Single(cfg.RemoteForward);
Assert.Equal("foobar", cfg.RemoteForward[0].RelayName);
Assert.Equal(3000, cfg.RemoteForward[0].HostPort);
return 0;
});
CommandLineSettings.Run(new string[] { "-R", "foobar_foobar:3000" },
(settings) =>
{
var cfg = Config.LoadConfig(settings);
Assert.Single(cfg.RemoteForward);
Assert.Equal("foobar_foobar", cfg.RemoteForward[0].RelayName);
Assert.Equal(3000, cfg.RemoteForward[0].HostPort);
return 0;
});
CommandLineSettings.Run(new string[] { "-R", "foobar/foobar:3000" },
(settings) =>
{
var cfg = Config.LoadConfig(settings);
Assert.Single(cfg.RemoteForward);
Assert.Equal("foobar/foobar", cfg.RemoteForward[0].RelayName);
Assert.Equal(3000, cfg.RemoteForward[0].HostPort);
return 0;
});
CommandLineSettings.Run(new string[] { "-R", "foobar.foobar:3000" },
(settings) =>
{
var cfg = Config.LoadConfig(settings);
Assert.Single(cfg.RemoteForward);
Assert.Equal("foobar.foobar", cfg.RemoteForward[0].RelayName);
Assert.Equal(3000, cfg.RemoteForward[0].HostPort);
return 0;
});
CommandLineSettings.Run(new string[] { "-R", "foobar-foobar:3000" },
(settings) =>
{
var cfg = Config.LoadConfig(settings);
Assert.Single(cfg.RemoteForward);
Assert.Equal("foobar-foobar", cfg.RemoteForward[0].RelayName);
Assert.Equal(3000, cfg.RemoteForward[0].HostPort);
return 0;
});
}

[Fact]
public void CommandLineBadRemoteForwardTest()
{
Expand Down
Loading