Skip to content

Commit

Permalink
Adding credential-authorization get endpoints (#2556)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonruAlveus authored Sep 12, 2022
1 parent 098557b commit 063e85e
Show file tree
Hide file tree
Showing 9 changed files with 989 additions and 489 deletions.
986 changes: 497 additions & 489 deletions Octokit.AsyncPaginationExtension/Extensions.cs

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions Octokit.Reactive/Clients/IObservableOrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,37 @@ public interface IObservableOrganizationsClient
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="Organization"/></returns>
IObservable<Organization> Update(string org, OrganizationUpdate updateRequest);

/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
IObservable<OrganizationCredential> GetAllAuthorizations(string org);

/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <param name="options">Options for changing the API response</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
IObservable<OrganizationCredential> GetAllAuthorizations(string org, ApiOptions options);

/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <param name="login">Limits the list of credentials authorizations for an organization to a specific login</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
IObservable<OrganizationCredential> GetAllAuthorizations(string org, string login);

/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <param name="login">Limits the list of credentials authorizations for an organization to a specific login</param>
/// <param name="options">Options for changing the API response</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
IObservable<OrganizationCredential> GetAllAuthorizations(string org, string login, ApiOptions options);
}
}
63 changes: 63 additions & 0 deletions Octokit.Reactive/Clients/ObservableOrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,68 @@ public IObservable<Organization> Update(string org, OrganizationUpdate updateReq
return _client.Update(org, updateRequest).ToObservable();
}

/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
public IObservable<OrganizationCredential> GetAllAuthorizations(string org)
{
Ensure.ArgumentNotNull(org, nameof(org));

var url = ApiUrls.AllOrganizationCredentials(org);

return _connection.GetAndFlattenAllPages<OrganizationCredential>(url);
}

/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <param name="options">Options for changing the API response</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
public IObservable<OrganizationCredential> GetAllAuthorizations(string org, ApiOptions options)
{
Ensure.ArgumentNotNull(org, nameof(org));
Ensure.ArgumentNotNull(options, nameof(options));

var url = ApiUrls.AllOrganizationCredentials(org);

return _connection.GetAndFlattenAllPages<OrganizationCredential>(url, options);
}

/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <param name="login">Limits the list of credentials authorizations for an organization to a specific login</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
public IObservable<OrganizationCredential> GetAllAuthorizations(string org, string login)
{
Ensure.ArgumentNotNull(org, nameof(org));
Ensure.ArgumentNotNull(login, nameof(login));

var url = ApiUrls.AllOrganizationCredentials(org, login);

return _connection.GetAndFlattenAllPages<OrganizationCredential>(url);
}

/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <param name="login">Limits the list of credentials authorizations for an organization to a specific login</param>
/// <param name="options">Options for changing the API response</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
public IObservable<OrganizationCredential> GetAllAuthorizations(string org, string login, ApiOptions options)
{
Ensure.ArgumentNotNull(org, nameof(org));
Ensure.ArgumentNotNull(login, nameof(login));
Ensure.ArgumentNotNull(options, nameof(options));

var url = ApiUrls.AllOrganizationCredentials(org, login);

return _connection.GetAndFlattenAllPages<OrganizationCredential>(url, options);
}
}
}
97 changes: 97 additions & 0 deletions Octokit.Tests/Clients/OrganizationsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,102 @@ public async Task EnsuresNonNullArguments()
await Assert.ThrowsAsync<ArgumentException>(() => client.Update("", new OrganizationUpdate()));
}
}

public class TheGetAllAuthorizationsMethod
{
[Fact]
public async Task RequestTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationsClient(connection);

await client.GetAllAuthorizations("fake");

connection.Received().GetAll<OrganizationCredential>(Arg.Is<Uri>(u => u.ToString() == "orgs/fake/credential-authorizations"));
}

[Fact]
public async Task RequestTheCorrectUrlWithOptions()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationsClient(connection);

await client.GetAllAuthorizations("fake", new ApiOptions() { PageCount = 1, PageSize = 1, StartPage = 1});

connection.Received().GetAll<OrganizationCredential>(Arg.Is<Uri>(u => u.ToString() == "orgs/fake/credential-authorizations"), Args.ApiOptions);
}

[Fact]
public async Task RequestTheCorrectUrlWithLogin()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationsClient(connection);

await client.GetAllAuthorizations("fake", "login");

connection.Received().GetAll<OrganizationCredential>(Arg.Is<Uri>(u => u.ToString() == "orgs/fake/credential-authorizations?login=login"));
}

[Fact]
public async Task RequestTheCorrectUrlWithLoginAndUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationsClient(connection);

await client.GetAllAuthorizations("fake", "login", new ApiOptions() { PageCount = 1, PageSize = 1, StartPage = 1 });

connection.Received().GetAll<OrganizationCredential>(Arg.Is<Uri>(u => u.ToString() == "orgs/fake/credential-authorizations?login=login"), Args.ApiOptions);
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationsClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAuthorizations(null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllAuthorizations(""));
}

[Fact]
public async Task EnsuresNonNullArgumentsWithOptions()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationsClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAuthorizations(null, new ApiOptions()));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllAuthorizations("", new ApiOptions()));

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAuthorizations("asd", (ApiOptions)null));
}

[Fact]
public async Task EnsuresNonNullArgumentsWithLogin()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationsClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAuthorizations(null, "asd"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllAuthorizations("", "asd"));

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAuthorizations("asd", (string)null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllAuthorizations("asd", ""));
}

[Fact]
public async Task EnsuresNonNullArgumentsWithLoginAndOptions()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationsClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAuthorizations(null, "asd", new ApiOptions()));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllAuthorizations("", "asd", new ApiOptions()));

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAuthorizations("asd", (string)null, new ApiOptions()));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllAuthorizations("asd", "", new ApiOptions()));

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAuthorizations("asd", "asd", null));
}
}
}
}
76 changes: 76 additions & 0 deletions Octokit.Tests/Reactive/ObservableOrganizationsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,81 @@ public void EnsuresNonNullArguments()
Assert.Throws<ArgumentException>(() => client.Update("", new OrganizationUpdate()));
}
}

public class TheGetAllAuthorizationsMethod
{
[Fact]
public void RequestsTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableOrganizationsClient(gitHubClient);

client.GetAllAuthorizations("org");

gitHubClient.Received().Organization.GetAllAuthorizations("org");
}

[Fact]
public void RequestsTheCorrectUrlWithApiOptions()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableOrganizationsClient(gitHubClient);

var options = new ApiOptions
{
StartPage = 1,
PageCount = 1,
PageSize = 1
};

client.GetAllAuthorizations("org", options);

gitHubClient.Received().Organization.GetAllAuthorizations("org", options);
}

[Fact]
public void RequestsTheCorrectUrlWithLogin()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableOrganizationsClient(gitHubClient);

client.GetAllAuthorizations("org", "login");

gitHubClient.Received().Organization.GetAllAuthorizations("org", "login");
}

[Fact]
public void RequestsTheCorrectUrlWithApiOptionsWithLogin()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableOrganizationsClient(gitHubClient);

var options = new ApiOptions
{
StartPage = 1,
PageCount = 1,
PageSize = 1
};

client.GetAllAuthorizations("org", "login", options);

gitHubClient.Received().Organization.GetAllAuthorizations("org", "login", options);
}

[Fact]
public void EnsuresNonNullArguments()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableOrganizationsClient(gitHubClient);

Assert.Throws<ArgumentNullException>(() => client.GetAllAuthorizations(null));
Assert.Throws<ArgumentNullException>(() => client.GetAllAuthorizations(null, ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => client.GetAllAuthorizations("username", (string)null));
Assert.Throws<ArgumentNullException>(() => client.GetAllAuthorizations("username", null, ApiOptions.None));

Assert.Throws<ArgumentNullException>(() => client.GetAllAuthorizations("asd", (ApiOptions)null));
Assert.Throws<ArgumentNullException>(() => client.GetAllAuthorizations("asd", "asd", null));
}
}
}
}
32 changes: 32 additions & 0 deletions Octokit/Clients/IOrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,37 @@ public interface IOrganizationsClient
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="Organization"/></returns>
Task<Organization> Update(string org, OrganizationUpdate updateRequest);

/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
Task<IReadOnlyList<OrganizationCredential>> GetAllAuthorizations(string org);

/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <param name="options">Options for changing the API response</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
Task<IReadOnlyList<OrganizationCredential>> GetAllAuthorizations(string org, ApiOptions options);

/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <param name="login">Limits the list of credentials authorizations for an organization to a specific login</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
Task<IReadOnlyList<OrganizationCredential>> GetAllAuthorizations(string org, string login);

/// <summary>
/// Returns all <see cref="OrganizationCredential" />s.
/// </summary>
/// <param name="org">The organization name.</param>
/// <param name="login">Limits the list of credentials authorizations for an organization to a specific login</param>
/// <param name="options">Options for changing the API response</param>
/// <returns>A list of <see cref="OrganizationCredential"/>s.</returns>
Task<IReadOnlyList<OrganizationCredential>> GetAllAuthorizations(string org, string login, ApiOptions options);
}
}
Loading

0 comments on commit 063e85e

Please sign in to comment.