Skip to content

Commit

Permalink
release: v0.12
Browse files Browse the repository at this point in the history
- feat: regenerate from latest API Document, changes include:
    - documentation fixes
    - types that represent enabling wildcards in authorization models
- fix: send authorization header to server when ApiToken used (openfga/sdk-generator#58)
- chore: update test dependencies
  • Loading branch information
rhamzeh committed Nov 15, 2022
1 parent 1c8d526 commit f264ab9
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 28 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## v0.1.2

### [0.1.2](https://github.com/openfga/dotnet-sdk/compare/v0.1.1...v0.1.2) (2022-11-15)

- feat: regenerate from latest API Document, changes include:
- documentation fixes
- types that represent enabling wildcards in authorization models
- fix: send authorization header to server when ApiToken used (https://github.com/openfga/sdk-generator/issues/58)
- chore: update test dependencies

## v0.1.1

### [0.1.1](https://github.com/openfga/dotnet-sdk/compare/v0.1.0...v0.1.1) (2022-10-07)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ var response = await openFgaApi.ListObjects(body);
| [**DeleteStore**](docs/OpenFgaApi.md#deletestore) | **DELETE** /stores/{store_id} | Delete a store |
| [**Expand**](docs/OpenFgaApi.md#expand) | **POST** /stores/{store_id}/expand | Expand all relationships in userset tree format, and following userset rewrite rules. Useful to reason about and debug a certain relationship |
| [**GetStore**](docs/OpenFgaApi.md#getstore) | **GET** /stores/{store_id} | Get a store |
| [**ListObjects**](docs/OpenFgaApi.md#listobjects) | **POST** /stores/{store_id}/list-objects | ListObjects lists all of the object ids for objects of the provided type that the given user has a specific relation with. |
| [**ListObjects**](docs/OpenFgaApi.md#listobjects) | **POST** /stores/{store_id}/list-objects | [EXPERIMENTAL] Get all object ids of the given type that the user has a relation with |
| [**ListStores**](docs/OpenFgaApi.md#liststores) | **GET** /stores | Get all stores |
| [**Read**](docs/OpenFgaApi.md#read) | **POST** /stores/{store_id}/read | Get tuples from the store that matches a query, without following userset rewrite rules |
| [**ReadAssertions**](docs/OpenFgaApi.md#readassertions) | **GET** /stores/{store_id}/assertions/{authorization_model_id} | Read assertions for an authorization model ID |
Expand Down
16 changes: 9 additions & 7 deletions docs/OpenFgaApi.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/RelationReference.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Type** | **string** | |
**Relation** | **string** | | [optional]
**Wildcard** | **Object** | | [optional]

[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md)

65 changes: 58 additions & 7 deletions src/OpenFga.Sdk.Test/Api/OpenFgaApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading;
Expand Down Expand Up @@ -149,6 +150,55 @@ public void ValidApiTokenIssuerWellFormed() {
Assert.Equal("Configuration.ApiTokenIssuer does not form a valid URI (https://https://tokenissuer.fga.example)", exception.Message);
}

/// <summary>
/// Test that the authorization header is being sent
/// </summary>
[Fact]
public async Task ApiTokenSentInHeader() {
var mockHandler = new Mock<HttpMessageHandler>(MockBehavior.Strict);
var config = new Configuration.Configuration() {
StoreId = _storeId,
ApiHost = _host,
Credentials = new Credentials() {
Method = CredentialsMethod.ApiToken,
Config = new CredentialsConfig() {
ApiToken = "some-token"
}
}
};

var readAuthorizationModelsMockExpression = ItExpr.Is<HttpRequestMessage>(req =>
req.RequestUri.ToString()
.StartsWith($"{config.BasePath}/stores/{config.StoreId}/authorization-models") &&
req.Method == HttpMethod.Get &&
req.Headers.Contains("Authorization") &&
req.Headers.Authorization.Equals(new AuthenticationHeaderValue("Bearer", "some-token")));

mockHandler.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
readAuthorizationModelsMockExpression,
ItExpr.IsAny<CancellationToken>()
)
.ReturnsAsync(new HttpResponseMessage() {
StatusCode = HttpStatusCode.OK,
Content = Utils.CreateJsonStringContent(
new ReadAuthorizationModelsResponse() { AuthorizationModels = { } }),
});

var httpClient = new HttpClient(mockHandler.Object);
var openFga = new OpenFgaApi(config, httpClient);

var response = await openFga.ReadAuthorizationModels(null, null);

mockHandler.Protected().Verify(
"SendAsync",
Times.Exactly(1),
readAuthorizationModelsMockExpression,
ItExpr.IsAny<CancellationToken>()
);
}

/// <summary>
/// Test that providing no client id, secret, api token issuer or api audience when they are required should error
/// </summary>
Expand Down Expand Up @@ -269,13 +319,16 @@ public async Task ExchangeCredentialsTest() {
}),
});

var readAuthorizationModelsMockExpression = ItExpr.Is<HttpRequestMessage>(req =>
req.RequestUri.ToString()
.StartsWith($"{config.BasePath}/stores/{config.StoreId}/authorization-models") &&
req.Method == HttpMethod.Get &&
req.Headers.Contains("Authorization") &&
req.Headers.Authorization.Equals(new AuthenticationHeaderValue("Bearer", "some-token")));
mockHandler.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.Is<HttpRequestMessage>(req =>
req.RequestUri.ToString()
.StartsWith($"{config.BasePath}/stores/{config.StoreId}/authorization-models") &&
req.Method == HttpMethod.Get),
readAuthorizationModelsMockExpression,
ItExpr.IsAny<CancellationToken>()
)
.ReturnsAsync(new HttpResponseMessage() {
Expand All @@ -300,9 +353,7 @@ public async Task ExchangeCredentialsTest() {
mockHandler.Protected().Verify(
"SendAsync",
Times.Exactly(1),
ItExpr.Is<HttpRequestMessage>(req =>
req.RequestUri.ToString().StartsWith($"{config.BasePath}/stores/{config.StoreId}/authorization-models") &&
req.Method == HttpMethod.Get),
readAuthorizationModelsMockExpression,
ItExpr.IsAny<CancellationToken>()
);
mockHandler.Protected().Verify(
Expand Down
2 changes: 1 addition & 1 deletion src/OpenFga.Sdk.Test/OpenFga.Sdk.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
Expand Down
Loading

0 comments on commit f264ab9

Please sign in to comment.