Skip to content

Commit

Permalink
Rework tests. Note that test user and distinguished names have been r…
Browse files Browse the repository at this point in the history
…eplaced with generic values as we cant reveal our own domain details
  • Loading branch information
ryangribble committed Feb 8, 2016
1 parent 50a9384 commit 4e3d243
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
using Octokit.Tests.Integration.Helpers;
using Xunit;

public class EnterpriseLdapClientTests
public class EnterpriseLdapClientTests : IDisposable
{
readonly IGitHubClient _github;
readonly EnterpriseTeamContext _context;

readonly string _testUser = "test-user";
readonly string _distinguishedNameUser = "uid=test-user,ou=users,dc=company,dc=com";
readonly string _distinguishedNameTeam = "uid=DG-Test-Team,ou=groups,dc=company,dc=com";

readonly EnterpriseTeamContext _context;
readonly string _distinguishedNameTeam = "cn=test-team,ou=groups,dc=company,dc=com";

public EnterpriseLdapClientTests()
{
Expand All @@ -26,26 +29,28 @@ public async Task CanUpdateUserMapping()
{
var newLDAPMapping = new NewLdapMapping(_distinguishedNameUser);
var ldapUser = await
_github.Enterprise.Ldap.UpdateUserMapping(EnterpriseHelper.UserName, newLDAPMapping);
_github.Enterprise.Ldap.UpdateUserMapping(_testUser, newLDAPMapping);

Assert.NotNull(ldapUser);
Assert.NotNull(ldapUser.LdapDn);
Assert.Equal(ldapUser.LdapDn, _distinguishedNameUser);

// Get user and check mapping was updated
var checkUser = await _github.User.Get(EnterpriseHelper.UserName);
var checkUser = await _github.User.Get(_testUser);
Assert.Equal(checkUser.Login, ldapUser.Login);
//Assert.Equal(checkUser.LdapDN, _distinguishedNameUser);
Assert.Equal(checkUser.LdapDn, _distinguishedNameUser);
}

[GitHubEnterpriseTest]
public async Task CanQueueSyncUserMapping()
{
var response = await
_github.Enterprise.Ldap.QueueSyncUserMapping(EnterpriseHelper.UserName);
_github.Enterprise.Ldap.QueueSyncUserMapping(_testUser);

// Check response message indicates LDAP sync was queued
Assert.NotNull(response);
Assert.NotNull(response.Status);
Assert.True(response.Status.All(m => m.Contains("was added to the indexing queue")));
Assert.True(response.Status == "queued");
}

[GitHubEnterpriseTest]
Expand All @@ -56,11 +61,13 @@ public async Task CanUpdateTeamMapping()
_github.Enterprise.Ldap.UpdateTeamMapping(_context.TeamId, newLDAPMapping);

Assert.NotNull(ldapTeam);
Assert.NotNull(ldapTeam.LdapDn);
Assert.Equal(ldapTeam.LdapDn, _distinguishedNameTeam);

// Get Team and check mapping was updated
var checkTeam = await _github.Organization.Team.Get(_context.TeamId);
Assert.Equal(checkTeam.Name, ldapTeam.Name);
//Assert.Equal(checkTeam.LDAPDN, _fixtureDistinguishedNameTeam);
Assert.Equal(checkTeam.LdapDn, _distinguishedNameTeam);
}

[GitHubEnterpriseTest]
Expand All @@ -72,6 +79,11 @@ public async Task CanQueueSyncTeamMapping()
// Check response message indicates LDAP sync was queued
Assert.NotNull(response);
Assert.NotNull(response.Status);
Assert.True(response.Status.All(m => m.Contains("was added to the indexing queue")));
Assert.True(response.Status == "queued");
}

public void Dispose()
{
_context.Dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

namespace Octokit.Tests.Integration
{
public class ObservableEnterpriseLdapClientTests
public class ObservableEnterpriseLdapClientTests : IDisposable
{
readonly IObservableGitHubClient _github;
readonly EnterpriseTeamContext _context;
readonly string _distinguishedNameUser = "uid=test-user,ou=users,dc=company,dc=com";
readonly string _distinguishedNameTeam = "uid=DG-Test-Team,ou=groups,dc=company,dc=com";

readonly string _testUser = "test-user";
readonly string _distinguishedNameUser = "uid=test-user,ou=users,dc=company,dc=com";

readonly EnterpriseTeamContext _context;
readonly string _distinguishedNameTeam = "cn=test-team,ou=groups,dc=company,dc=com";

public ObservableEnterpriseLdapClientTests()
{
var gitHub = EnterpriseHelper.GetAuthenticatedClient();
Expand All @@ -29,28 +32,30 @@ public async Task CanUpdateUserMapping()
{
var newLDAPMapping = new NewLdapMapping(_distinguishedNameUser);
var observable =
_github.Enterprise.Ldap.UpdateUserMapping(EnterpriseHelper.UserName, newLDAPMapping);
_github.Enterprise.Ldap.UpdateUserMapping(_testUser, newLDAPMapping);
var ldapUser = await observable;

Assert.NotNull(ldapUser);
Assert.NotNull(ldapUser.LdapDn);
Assert.Equal(ldapUser.LdapDn, _distinguishedNameUser);

// Get user and check mapping was updated
var checkUser = await _github.User.Get(EnterpriseHelper.UserName);
var checkUser = await _github.User.Get(_testUser);
Assert.Equal(checkUser.Login, ldapUser.Login);
//Assert.Equal(checkUser.LdapDN, _distinguishedNameUser);
Assert.Equal(checkUser.LdapDn, _distinguishedNameUser);
}

[GitHubEnterpriseTest]
public async Task CanQueueSyncUserMapping()
{
var observable =
_github.Enterprise.Ldap.QueueSyncUserMapping(EnterpriseHelper.UserName);
_github.Enterprise.Ldap.QueueSyncUserMapping(_testUser);
var response = await observable;

// Check response message indicates LDAP sync was queued
Assert.NotNull(response);
Assert.NotNull(response.Status);
Assert.True(response.Status.All(m => m.Contains("was added to the indexing queue")));
Assert.True(response.Status == "queued");
}

[GitHubEnterpriseTest]
Expand All @@ -62,11 +67,13 @@ public async Task CanUpdateTeamMapping()
var ldapTeam = await observable;

Assert.NotNull(ldapTeam);
Assert.NotNull(ldapTeam.LdapDn);
Assert.Equal(ldapTeam.LdapDn, _distinguishedNameTeam);

// Get Team and check mapping was updated
var checkTeam = await _github.Organization.Team.Get(_context.TeamId);
Assert.Equal(checkTeam.Name, ldapTeam.Name);
//Assert.Equal(checkTeam.LdapDN, _distinguishedNameTeam);
Assert.Equal(checkTeam.LdapDn, _distinguishedNameTeam);
}

[GitHubEnterpriseTest]
Expand All @@ -79,7 +86,12 @@ public async Task CanQueueSyncTeamMapping()
// Check response message indicates LDAP sync was queued
Assert.NotNull(response);
Assert.NotNull(response.Status);
Assert.True(response.Status.All(m => m.Contains("was added to the indexing queue")));
Assert.True(response.Status == "queued");
}

public void Dispose()
{
_context.Dispose();
}
}
}
12 changes: 6 additions & 6 deletions Octokit.Tests/Clients/Enterprise/EnterpriseLdapClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void RequestsCorrectUrl()
string expectedUri = "admin/ldap/users/test-user/mapping";
client.UpdateUserMapping("test-user", new NewLdapMapping(_distinguishedNameUser));

connection.Received().Patch<LdapUser>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
connection.Received().Patch<User>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}

[Fact]
Expand All @@ -31,10 +31,10 @@ public void PassesRequestObject()

client.UpdateUserMapping("test-user", new NewLdapMapping(_distinguishedNameUser));

connection.Received().Patch<LdapUser>(
connection.Received().Patch<User>(
Arg.Any<Uri>(),
Arg.Is<NewLdapMapping>(a =>
a.LdapDN == _distinguishedNameUser));
a.LdapDn == _distinguishedNameUser));
}

[Fact]
Expand Down Expand Up @@ -86,7 +86,7 @@ public void RequestsCorrectUrl()
string expectedUri = "admin/ldap/teams/1/mapping";
client.UpdateTeamMapping(1, new NewLdapMapping(_distinguishedNameTeam));

connection.Received().Patch<LdapTeam>(
connection.Received().Patch<Team>(
Arg.Is<Uri>(u => u.ToString() == expectedUri),
Arg.Any<object>());
}
Expand All @@ -99,10 +99,10 @@ public void PassesRequestObject()

client.UpdateTeamMapping(1, new NewLdapMapping(_distinguishedNameTeam));

connection.Received().Patch<LdapTeam>(
connection.Received().Patch<Team>(
Arg.Any<Uri>(),
Arg.Is<NewLdapMapping>(a =>
a.LdapDN == _distinguishedNameTeam));
a.LdapDn == _distinguishedNameTeam));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void CallsIntoClient()
github.Enterprise.Ldap.Received(1).UpdateUserMapping(
Arg.Is<string>(a => a == "test-user"),
Arg.Is<NewLdapMapping>(a =>
a.LdapDN == _distinguishedName));
a.LdapDn == _distinguishedName));
}
}

Expand All @@ -41,7 +41,7 @@ public void CallsIntoClient()

public class TheUpdateTeamMappingMethod
{
readonly string _distinguishedName = "uid=DG-Test-Team,ou=groups,dc=company,dc=com";
readonly string _distinguishedName = "cn=test-team,ou=groups,dc=company,dc=com";

[Fact]
public void CallsIntoClient()
Expand All @@ -53,7 +53,7 @@ public void CallsIntoClient()
github.Enterprise.Ldap.Received(1).UpdateTeamMapping(
Arg.Is<int>(a => a == 1),
Arg.Is<NewLdapMapping>(a =>
a.LdapDN == _distinguishedName));
a.LdapDn == _distinguishedName));
}
}

Expand Down

0 comments on commit 4e3d243

Please sign in to comment.