This repository has been archived by the owner on Sep 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for authentication
This also changes the exception thrown for missing credentials when authentication is required to InvalidOperationException.
- Loading branch information
1 parent
f324f7c
commit 29d783c
Showing
4 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
test/Gremlin.Net.IntegrationTest/GremlinClientAuthenticationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Gremlin.Net.Exceptions; | ||
using Gremlin.Net.IntegrationTest.Util; | ||
using Xunit; | ||
|
||
namespace Gremlin.Net.IntegrationTest | ||
{ | ||
public class GremlinClientAuthenticationTests | ||
{ | ||
private static readonly string TestHost = ConfigProvider.Configuration["TestServerIpAddress"]; | ||
private static readonly int TestPort = Convert.ToInt32(ConfigProvider.Configuration["TestSecureServerPort"]); | ||
private readonly ScriptRequestMessageProvider _requestMessageProvider = new ScriptRequestMessageProvider(); | ||
|
||
[Fact] | ||
public async Task ShouldThrowForMissingCredentials() | ||
{ | ||
var gremlinServer = new GremlinServer(TestHost, TestPort); | ||
using (var gremlinClient = new GremlinClient(gremlinServer)) | ||
{ | ||
var exception = await Assert.ThrowsAsync<InvalidOperationException>( | ||
async () => await gremlinClient.SubmitWithSingleResultAsync<string>(_requestMessageProvider | ||
.GetDummyMessage())); | ||
|
||
Assert.Contains("authentication", exception.Message); | ||
Assert.Contains("credentials", exception.Message); | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData("unknownUser", "passwordDoesntMatter")] | ||
[InlineData("stephen", "wrongPassword")] | ||
public async Task ShouldThrowForWrongCredentials(string username, string password) | ||
{ | ||
var gremlinServer = new GremlinServer(TestHost, TestPort, Username: username, Password: password); | ||
using (var gremlinClient = new GremlinClient(gremlinServer)) | ||
{ | ||
var exception = await Assert.ThrowsAsync<ResponseException>( | ||
async () => await gremlinClient.SubmitWithSingleResultAsync<string>(_requestMessageProvider | ||
.GetDummyMessage())); | ||
|
||
Assert.Contains("Unauthorized", exception.Message); | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData("1+1", "2")] | ||
[InlineData("'Hello' + 'World'", "HelloWorld")] | ||
public async Task ScriptShouldBeEvaluatedAndResultReturnedForCorrectCredentials(string requestMsg, | ||
string expectedResponse) | ||
{ | ||
const string username = "stephen"; | ||
const string password = "password"; | ||
var gremlinServer = new GremlinServer(TestHost, TestPort, Username: username, Password: password); | ||
using (var gremlinClient = new GremlinClient(gremlinServer)) | ||
{ | ||
var response = await gremlinClient.SubmitWithSingleResultAsync<string>(requestMsg); | ||
|
||
Assert.Equal(expectedResponse, response); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"TestServerIpAddress": "localhost", | ||
"TestServerPort": 8182 | ||
"TestServerPort": 8182, | ||
"TestSecureServerPort": 8183 | ||
} |