Skip to content

Commit

Permalink
resolves #826
Browse files Browse the repository at this point in the history
  • Loading branch information
HEskandari committed May 23, 2019
1 parent 865dfd6 commit 0bbd729
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/ServiceInsight.Tests/CommandLineArgParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ public void Strips_application_path_from_the_command_line_args()
sut.ParsedOptions.EndpointUri.ToString().ShouldBe(ExpectedUri);
}

[Test]
public void Can_switch_to_secured_connection()
{
const string Options = "SecuredConnection=True";
const string Uri = "localhost:12345";
var invocationParameters = $"{SchemaPrefix}{Uri}?{Options}";

environment.GetCommandLineArgs().Returns(new[] { AppPath, invocationParameters });

var sut = CreateSut();

sut.ParsedOptions.SecuredConnection.ShouldBe(true);
sut.ParsedOptions.EndpointUri.Scheme.ShouldBe("https", Case.Insensitive);
}

[Test]
[TestCase("localhost")]
[TestCase("127.0.0.1")]
Expand Down
14 changes: 13 additions & 1 deletion src/ServiceInsight/Models/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class CommandLineOptions

public bool ResetLayout { get; private set; }

public bool SecuredConnection { get; private set; }

public void SetEndpointUri(string value)
{
if (string.IsNullOrWhiteSpace(value))
Expand All @@ -32,7 +34,7 @@ public void SetEndpointUri(string value)

if (value.StartsWith(ApplicationScheme, StringComparison.OrdinalIgnoreCase))
{
address = value.Replace(ApplicationScheme, "http://");
address = value.Replace(ApplicationScheme, GetConnectionScheme());
}

var regex = new Regex(UriRegexPattern);
Expand All @@ -42,6 +44,11 @@ public void SetEndpointUri(string value)
}
}

private string GetConnectionScheme()
{
return SecuredConnection ? "https://" : "http://";
}

public void SetEndpointName(string value)
{
EndpointName = Decode(value);
Expand All @@ -63,6 +70,11 @@ public void SetResetLayout(bool value)
ResetLayout = value;
}

public void SetSecuredConnection(bool value)
{
SecuredConnection = value;
}

string Decode(string encodedString) => HttpUtility.UrlDecode(encodedString);
}
}
14 changes: 9 additions & 5 deletions src/ServiceInsight/Startup/CommandLineArgParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ public void Parse()
return;
}

if (uri.Length > 0)
{
ParsedOptions.SetEndpointUri(uri[0]);
}

if (uri.Length > 1)
{
var parameters = uri[1];
Expand All @@ -61,6 +56,11 @@ public void Parse()
}
}
}

if (uri.Length > 0) //should be done last
{
ParsedOptions.SetEndpointUri(uri[0]);
}
}

void PopulateKeyValue(string key, string value)
Expand All @@ -69,6 +69,10 @@ void PopulateKeyValue(string key, string value)

switch (parameter)
{
case "securedconnection":
ParsedOptions.SetSecuredConnection(bool.Parse(value));
break;

case "search":
ParsedOptions.SetSearchQuery(value);
break;
Expand Down

0 comments on commit 0bbd729

Please sign in to comment.