forked from octokit/octokit.net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better support for GitHub Enterprise integration tests
- Remove EnterpriseUrl in integration test Helper class, but leave ability to override custom URL (to allow specific use case of targetting regular integration tests at a custom URL) - Move GitHub Enterprise explicit support to a new integration helper class using new OCTOKIT_GHE_ environment variables for GHE - Change existing GitHub Enterprise integration tests and EnterpriseTestAttribute to use the new EnterpriseHelper methods - Enhance configure-intergration-tests.ps1 script to cater for environment variable changes
- Loading branch information
1 parent
5f2cc4c
commit 535709c
Showing
7 changed files
with
198 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
|
||
namespace Octokit.Tests.Integration | ||
{ | ||
public static class EnterpriseHelper | ||
{ | ||
static readonly Lazy<Credentials> _credentialsThunk = new Lazy<Credentials>(() => | ||
{ | ||
var githubUsername = Environment.GetEnvironmentVariable("OCTOKIT_GHE_USERNAME"); | ||
GHEUserName = githubUsername; | ||
GHEOrganization = Environment.GetEnvironmentVariable("OCTOKIT_GHE_ORGANIZATION"); | ||
|
||
var githubToken = Environment.GetEnvironmentVariable("OCTOKIT_GHE_OAUTHTOKEN"); | ||
|
||
if (githubToken != null) | ||
return new Credentials(githubToken); | ||
|
||
var githubPassword = Environment.GetEnvironmentVariable("OCTOKIT_GHE_PASSWORD"); | ||
|
||
if (githubUsername == null || githubPassword == null) | ||
return null; | ||
|
||
return new Credentials(githubUsername, githubPassword); | ||
}); | ||
|
||
static readonly Lazy<Credentials> _oauthApplicationCredentials = new Lazy<Credentials>(() => | ||
{ | ||
var applicationClientId = ClientId; | ||
var applicationClientSecret = ClientSecret; | ||
|
||
if (applicationClientId == null || applicationClientSecret == null) | ||
return null; | ||
|
||
return new Credentials(applicationClientId, applicationClientSecret); | ||
}); | ||
|
||
static readonly Lazy<Credentials> _basicAuthCredentials = new Lazy<Credentials>(() => | ||
{ | ||
var githubUsername = Environment.GetEnvironmentVariable("OCTOKIT_GHE_USERNAME"); | ||
GHEUserName = githubUsername; | ||
GHEOrganization = Environment.GetEnvironmentVariable("OCTOKIT_GHE_ORGANIZATION"); | ||
|
||
var githubPassword = Environment.GetEnvironmentVariable("OCTOKIT_GHE_PASSWORD"); | ||
|
||
if (githubUsername == null || githubPassword == null) | ||
return null; | ||
|
||
return new Credentials(githubUsername, githubPassword); | ||
}); | ||
|
||
static readonly Lazy<bool> _gitHubEnterpriseEnabled = new Lazy<bool>(() => | ||
{ | ||
string enabled = Environment.GetEnvironmentVariable("OCTOKIT_GHE_ENABLED"); | ||
return !String.IsNullOrWhiteSpace(enabled); | ||
}); | ||
|
||
static readonly Lazy<Uri> _gitHubEnterpriseUrl = new Lazy<Uri>(() => | ||
{ | ||
string uri = Environment.GetEnvironmentVariable("OCTOKIT_GHE_URL"); | ||
|
||
if (uri != null) | ||
return new Uri(uri); | ||
|
||
return null; | ||
}); | ||
|
||
static EnterpriseHelper() | ||
{ | ||
// Force reading of environment variables. | ||
// This wasn't happening if UserName/Organization were | ||
// retrieved before Credentials. | ||
Debug.WriteIf(GHECredentials == null, "No credentials specified."); | ||
} | ||
|
||
public static string GHEUserName { get; private set; } | ||
public static string GHEOrganization { get; private set; } | ||
|
||
/// <summary> | ||
/// These credentials should be set to a test GitHub account using the powershell script configure-integration-tests.ps1 | ||
/// </summary> | ||
public static Credentials GHECredentials { get { return _credentialsThunk.Value; } } | ||
|
||
public static Credentials GHEApplicationCredentials { get { return _oauthApplicationCredentials.Value; } } | ||
|
||
public static Credentials GHEBasicAuthCredentials { get { return _basicAuthCredentials.Value; } } | ||
|
||
public static bool IsGitHubEnterpriseEnabled { get { return _gitHubEnterpriseEnabled.Value; } } | ||
|
||
public static Uri GitHubEnterpriseUrl { get { return _gitHubEnterpriseUrl.Value; } } | ||
|
||
public static bool IsUsingToken | ||
{ | ||
get | ||
{ | ||
return !String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("OCTOKIT_GHE_OAUTHTOKEN")); | ||
} | ||
} | ||
|
||
public static string ClientId | ||
{ | ||
get { return Environment.GetEnvironmentVariable("OCTOKIT_GHE_CLIENTID"); } | ||
} | ||
|
||
public static string ClientSecret | ||
{ | ||
get { return Environment.GetEnvironmentVariable("OCTOKIT_GHE_CLIENTSECRET"); } | ||
} | ||
|
||
public static void DeleteRepo(Repository repository) | ||
{ | ||
if (repository != null) | ||
DeleteRepo(repository.Owner.Login, repository.Name); | ||
} | ||
|
||
public static void DeleteRepo(string owner, string name) | ||
{ | ||
var api = GetAuthenticatedClient(); | ||
try | ||
{ | ||
api.Repository.Delete(owner, name).Wait(TimeSpan.FromSeconds(15)); | ||
} | ||
catch { } | ||
} | ||
|
||
public static IGitHubClient GetAuthenticatedClient() | ||
{ | ||
return new GitHubClient(new ProductHeaderValue("OctokitEnterpriseTests"), GitHubEnterpriseUrl) | ||
{ | ||
Credentials = GHECredentials | ||
}; | ||
} | ||
|
||
public static IGitHubClient GetBasicAuthClient() | ||
{ | ||
return new GitHubClient(new ProductHeaderValue("OctokitEnterpriseTests"), GitHubEnterpriseUrl) | ||
{ | ||
Credentials = GHEBasicAuthCredentials | ||
}; | ||
} | ||
|
||
public static GitHubClient GetAuthenticatedApplicationClient() | ||
{ | ||
return new GitHubClient(new ProductHeaderValue("OctokitEnterpriseTests"), GitHubEnterpriseUrl) | ||
{ | ||
Credentials = GHEApplicationCredentials | ||
}; | ||
} | ||
|
||
public static IGitHubClient GetAnonymousClient() | ||
{ | ||
return new GitHubClient(new ProductHeaderValue("OctokitEnterpriseTests"), GitHubEnterpriseUrl); | ||
} | ||
|
||
public static IGitHubClient GetBadCredentialsClient() | ||
{ | ||
return new GitHubClient(new ProductHeaderValue("OctokitEnterpriseTests"), GitHubEnterpriseUrl) | ||
{ | ||
Credentials = new Credentials(Guid.NewGuid().ToString(), "bad-password") | ||
}; | ||
} | ||
} | ||
} |
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
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
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