Skip to content

Instantly share code, notes, and snippets.

@heemskerkerik
Last active October 29, 2015 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heemskerkerik/f03f96e384933e3f5123 to your computer and use it in GitHub Desktop.
Save heemskerkerik/f03f96e384933e3f5123 to your computer and use it in GitHub Desktop.
RavenDB test: Batch-loading when using read-only API key authentication
using System.Linq;
using Raven.Abstractions.Data;
using Raven.Client.Document;
using Raven.Database.Config;
using Raven.Tests.Helpers;
using Xunit;
// ReSharper disable InconsistentNaming
namespace Raven.ReadOnlyBatchLoadFailure
{
public class OAuthReadOnlyAuthenticationBatchLoadTest: RavenTestBase
{
[Fact]
public void OAuthReadOnlyAccess_BatchLoadSucceeds()
{
using (var server = GetNewServer(configureConfig: ConfigureOptions, enableAuthentication: true))
{
using (var store = NewRemoteDocumentStore(ravenDbServer: server, fiddler: true))
{
using (var session = store.OpenSession("<system>"))
{
session.Store(new ApiKeyDefinition
{
Id = "Raven/ApiKeys/Test",
Name = "Test",
Secret = "gFjepjuccNJu7vq6hnQyv4lNBUXpdLpC",
Enabled = true,
Databases =
{
new ResourceAccess
{
TenantId = "OAuthReadOnlyAccess_BatchLoadSucceeds",
Admin = false,
ReadOnly = true,
},
},
});
session.SaveChanges();
}
using (var apiKeyStore = NewRemoteDocumentStore(ravenDbServer: server, fiddler: true, configureStore: ConfigureDocumentStore))
{
using (var session = apiKeyStore.OpenSession())
{
session.Load<object>(Enumerable.Range(1, 100).Select(i => "Documents/" + i));
}
}
}
}
}
private void ConfigureOptions(InMemoryRavenConfiguration config)
{
config.Settings["Raven/Licensing/AllowAdminAnonymousAccessForCommercialUse"] = "true";
// valid license required because API key authentication is used. not included for obvious purposes.
config.Settings["Raven/License"] = @"";
}
private void ConfigureDocumentStore(DocumentStore store)
{
store.ApiKey = "Test/gFjepjuccNJu7vq6hnQyv4lNBUXpdLpC";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment