Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ayende/ravendb into 2.1
Browse files Browse the repository at this point in the history
Conflicts:
	Raven.Abstractions/Data/IJsonDocumentMetadata.cs
	Raven.Abstractions/Data/PutResult.cs
	Raven.Abstractions/Data/StringDistanceTypes.cs
	Raven.Abstractions/Exceptions/ConcurrencyException.cs
	Raven.Abstractions/Smuggler/SmugglerOptions.cs
	Raven.Client.Lightweight/Changes/RemoteDatabaseChanges.cs
	Raven.Client.Lightweight/Connection/HttpJsonRequestFactory.cs
	Raven.Client.Lightweight/Connection/ServerClient.cs
	Raven.Client.Lightweight/Document/AbstractDocumentQuery.cs
	Raven.Client.Lightweight/Document/InMemoryDocumentSessionOperations.cs
	Raven.Client.Lightweight/Document/RemoteBulkInsertOperation.cs
	Raven.Client.Lightweight/IAsyncDocumentSession.cs
	Raven.Client.Lightweight/Indexes/ExpressionStringBuilder.cs
	Raven.Client.Lightweight/Linq/LinqPathProvider.cs
	Raven.Client.Lightweight/PublicExtensions/LinqExtensions.cs
	Raven.Client.VisualBasic.Tests/Raven.Client.VisualBasic.Tests.vbproj
	Raven.Client.VisualBasic.Tests/packages.config
	Raven.Database/Data/AttachmentInformation.cs
	Raven.Database/Data/IndexQueryResult.cs
	Raven.Database/DocumentDatabase.cs
	Raven.Database/Extensions/AdminFinder.cs
	Raven.Database/Extensions/HttpContextExtensions.cs
	Raven.Database/Extensions/HttpExtensions.cs
	Raven.Database/Indexing/CurrentIndexingScope.cs
	Raven.Database/Indexing/IndexingExecuter.cs
	Raven.Database/Indexing/ReducingExecuter.cs
	Raven.Database/Plugins/Builtins/Tenants/ModifiedTenantDatabase.cs
	Raven.Database/Server/Responders/Docs.cs
	Raven.Database/Server/Responders/Facets.cs
	Raven.Database/Server/Security/OAuth/OAuthRequestAuthorizer.cs
	Raven.Database/Server/Security/Windows/WindowsRequestAuthorizer.cs
	Raven.Database/Storage/Esent/Backup/RestoreOperation.cs
	Raven.Database/Storage/Esent/StorageActions/Indexing.cs
	Raven.Database/Storage/Esent/StorageActions/Lists.cs
	Raven.Database/Storage/Esent/StorageActions/MappedResults.cs
	Raven.Database/Storage/Esent/TransactionalStorage.cs
	Raven.Database/Storage/IListsStorageActions.cs
	Raven.Database/Storage/Managed/ListsStorageActions.cs
	Raven.Database/Storage/Managed/MappedResultsStorageAction.cs
	Raven.Database/Storage/Managed/TransactionStorageActions.cs
	Raven.Server/App.config
	Raven.Studio/Controls/DateTimePicker.xaml
	Raven.Studio/Models/EditableDocumentModel.cs
	Raven.Studio/Models/ServerModel.cs
	Raven.Studio/Views/Edit.xaml
	Raven.Tests/App.config
	Raven.Tests/Bundles/Replication/Issues/RavenDB677.cs
	Raven.Tests/MailingList/IisQueryLengthIssues.cs
	Raven.Tests/Querying/UsingDynamicQueryWithRemoteServer.cs
	Raven.Tests/Storage/Lists.cs
	Raven.Tryouts/Program.cs
  • Loading branch information
ayende committed Feb 11, 2013
2 parents c2ad274 + f2a050b commit 00a379d
Show file tree
Hide file tree
Showing 498 changed files with 21,281 additions and 6,503 deletions.
104 changes: 104 additions & 0 deletions Bundles/Raven.Bundles.Tests/Authorization/Bugs/Matthew.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
extern alias client;
using Raven.Client.Exceptions;
using client::Raven.Bundles.Authorization.Model;
using System.Collections.Generic;
using Raven.Client;
using Xunit;

namespace Raven.Bundles.Tests.Authorization.Bugs
{
public class Matthew : AuthorizationTest
{
[Fact]
public void AuthorizationDemo_Works()
{
// Arrange
using (IDocumentSession session = store.OpenSession())
{
session.Store(
new AuthorizationRole
{
Id = "Authorization/Roles/Nurses",
Permissions =
{
new OperationPermission
{
Allow = true,
Operation = "Appointment/Schedule",
Tags = new List<string> {"Patient"}
}
}
});

// Allow doctors to authorize hospitalizations
session.Store(
new AuthorizationRole
{
Id = "Authorization/Roles/Doctors",
Permissions =
{
new OperationPermission
{
Allow = true,
Operation = "Hospitalization/Authorize",
Tags = new List<string> {"Patient"}
}
}
});
// Associate Patient with clinic
var maryMallon = new Patient {Id = "Patients/MaryMallon"};
session.Store(maryMallon);
client::Raven.Client.Authorization.AuthorizationClientExtensions.SetAuthorizationFor(session, maryMallon,
new DocumentAuthorization
{
Tags =
{
"Clinics/Kirya",
"Patient"
}
});

// Associate Doctor with clinic
session.Store(
new AuthorizationUser
{
Id = "Authorization/Users/DrHowser",
Name = "Doogie Howser",
Roles = {"Authorization/Roles/Doctors"},
Permissions =
{
new OperationPermission
{
Allow = true,
Operation = "Patient/View",
Tags = new List<string> {"Clinics/Kirya"}
},
}
});
session.SaveChanges();
}


// Assert
using (IDocumentSession session = store.OpenSession())
{
client::Raven.Client.Authorization.AuthorizationClientExtensions.SecureFor(session,
"Authorization/Users/NotDrHowser",
"Hospitalization/Authorize");
var readVetoException = Assert.Throws<ReadVetoException>(() => session.Load<Patient>("Patients/MaryMallon"));
Assert.Contains(
"Could not find user: Authorization/Users/NotDrHowser for secured document: Patients/MaryMallon",
readVetoException.Message);
}
}
}

public class Patient
{
public string Id { get; set; }

public void AuthorizeHospitalization()
{
}
}
}
1 change: 0 additions & 1 deletion Bundles/Raven.Bundles.Tests/Expiration/WithCascade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public WithCascade()
};
ravenConfiguration.PostInit();
ravenDbServer = new RavenDbServer(ravenConfiguration);
database::Raven.Bundles.Expiration.ExpirationReadTrigger.GetCurrentUtcDate = () => DateTime.UtcNow;
documentStore = new DocumentStore
{
Url = "http://localhost:8079"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public CanReplicateToSql()
}
};
documentStore.Initialize();
database::Raven.Bundles.Expiration.ExpirationReadTrigger.GetCurrentUtcDate = () => DateTime.UtcNow;

documentStore.DatabaseCommands.PutIndex(
"Questions/Votes",
Expand Down
1 change: 1 addition & 0 deletions Bundles/Raven.Bundles.Tests/Raven.Bundles.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<Compile Include="Authorization\Bugs\Jalchr.cs" />
<Compile Include="Authorization\Bugs\Kwal.cs" />
<Compile Include="Authorization\Bugs\LoadingSavedInfo.cs" />
<Compile Include="Authorization\Bugs\Matthew.cs" />
<Compile Include="Authorization\Bugs\WhenUsingMultiTenancy.cs" />
<Compile Include="Authorization\Bugs\WithChangingOfUser.cs" />
<Compile Include="Authorization\CanAskAuthQuestions.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extern alias database;
using System.Threading;
using Raven.Abstractions.Data;
using Raven.Client.Extensions;
using Raven.Tests.Bundles.Replication;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading;
using Raven.Abstractions.Data;
using Raven.Client.Extensions;
using Raven.Json.Linq;
using Raven.Tests.Bundles.Replication;
using Xunit;
Expand Down
2 changes: 1 addition & 1 deletion DefaultConfigs/RavenDb.exe.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<runtime>
<loadFromRemoteSources enabled="true"/>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="Analyzers"/>
<probing privatePath="Analyzers;Plugins"/>
</assemblyBinding>
</runtime>
</configuration>
2 changes: 1 addition & 1 deletion DefaultConfigs/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

<probing privatePath="Analyzers"/>
<probing privatePath="Analyzers;Plugins"/>

</assemblyBinding>

Expand Down
2 changes: 1 addition & 1 deletion Imports/Newtonsoft.Json/Src/Newtonsoft.Json/JsonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ protected JsonReader()
_currentState = State.Start;
_stack = new List<JsonPosition>(4);
_dateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
_dateParseHandling = DateParseHandling.DateTime;
_dateParseHandling = DateParseHandling.None;

CloseInput = true;
}
Expand Down
32 changes: 14 additions & 18 deletions Raven.Abstractions/Connection/HttpRavenRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,13 @@ public HttpRavenRequest(string url, string method, Action<RavenConnectionStringO

private HttpWebRequest CreateRequest()
{
var request = (HttpWebRequest) System.Net.WebRequest.Create(url);
var request = (HttpWebRequest)System.Net.WebRequest.Create(url);
request.Method = method;
if (method == "POST" || method == "PUT")
request.Headers["Content-Encoding"] = "gzip";
request.Headers["Accept-Encoding"] = "deflate,gzip";
request.ContentType = "application/json; charset=utf-8";

if (connectionStringOptions.Credentials != null)
request.Credentials = connectionStringOptions.Credentials;
else
request.UseDefaultCredentials = true;

configureRequest(connectionStringOptions, request);
return request;
}
Expand All @@ -65,8 +60,8 @@ public void Write(Stream streamToWrite)
{
postedStream = streamToWrite;
using (var stream = WebRequest.GetRequestStream())
using(var countingStream = new CountingStream(stream, l => NumberOfBytesWrittenCompressed = l))
using(var commpressedStream = new GZipStream(countingStream, CompressionMode.Compress))
using (var countingStream = new CountingStream(stream, l => NumberOfBytesWrittenCompressed = l))
using (var commpressedStream = new GZipStream(countingStream, CompressionMode.Compress))
using (var countingStream2 = new CountingStream(commpressedStream, l => NumberOfBytesWrittenUncompressed = l))
{
streamToWrite.CopyTo(countingStream2);
Expand Down Expand Up @@ -128,17 +123,17 @@ public T ExecuteRequest<T>()
{
T result = default(T);
SendRequestToServer(response =>
{
using (var stream = response.GetResponseStreamWithHttpDecompression())
using (var reader = new StreamReader(stream))
{
result = reader.JsonDeserialization<T>();
}
});
{
using (var stream = response.GetResponseStreamWithHttpDecompression())
using (var reader = new StreamReader(stream))
{
result = reader.JsonDeserialization<T>();
}
});
return result;
}

public void ExecuteRequest(Action<StreamReader> action)
public void ExecuteRequest(Action<TextReader> action)
{
SendRequestToServer(response =>
{
Expand Down Expand Up @@ -188,7 +183,8 @@ private void SendRequestToServer(Action<WebResponse> action)
if (response == null)
throw;

if (response.StatusCode != HttpStatusCode.Unauthorized)
if (response.StatusCode != HttpStatusCode.Unauthorized &&
response.StatusCode != HttpStatusCode.PreconditionFailed)
{
using (var streamReader = new StreamReader(response.GetResponseStreamWithHttpDecompression()))
{
Expand Down Expand Up @@ -235,7 +231,7 @@ private void RecreateWebRequest()
if (postedStream != null)
{
postedStream.Position = 0;
using (var stream = newWebRequest.GetRequestStream())
using (var stream = newWebRequest.GetRequestStream())
using (var compressedData = new GZipStream(stream, CompressionMode.Compress))
{
postedStream.CopyTo(compressedData);
Expand Down
62 changes: 29 additions & 33 deletions Raven.Abstractions/Connection/HttpRavenRequestFactory.cs
Original file line number Diff line number Diff line change
@@ -1,58 +1,54 @@
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Net;
using Raven.Abstractions.Data;
using Raven.Abstractions.OAuth;

namespace Raven.Abstractions.Connection
{
public class HttpRavenRequestFactory
{
public int? RequestTimeoutInMs { get; set; }

private bool RefreshOauthToken(RavenConnectionStringOptions options, WebResponse response)
readonly ConcurrentDictionary<string, SecuredAuthenticator> authenticators = new ConcurrentDictionary<string, SecuredAuthenticator>();

public void ConfigureRequest(RavenConnectionStringOptions options, WebRequest request)
{
var oauthSource = response.Headers["OAuth-Source"];
if (string.IsNullOrEmpty(oauthSource))
return false;
if (RequestTimeoutInMs.HasValue)
request.Timeout = RequestTimeoutInMs.Value;


var authRequest = PrepareOAuthRequest(options, oauthSource);
using (var authResponse = authRequest.GetResponse())
using (var stream = authResponse.GetResponseStreamWithHttpDecompression())
using (var reader = new StreamReader(stream))
if (options.ApiKey == null)
{
options.CurrentOAuthToken = "Bearer " + reader.ReadToEnd();
request.Credentials = options.Credentials ?? CredentialCache.DefaultNetworkCredentials;
return;
}
return true;
}

private HttpWebRequest PrepareOAuthRequest(RavenConnectionStringOptions options, string oauthSource)
{
var authRequest = (HttpWebRequest) WebRequest.Create(oauthSource);
authRequest.Credentials = options.Credentials;
authRequest.Headers["Accept-Encoding"] = "deflate,gzip";
authRequest.Accept = "application/json;charset=UTF-8";

authRequest.Headers["grant_type"] = "client_credentials";
var value = authenticators.GetOrAdd(options.ApiKey, s => new SecuredAuthenticator(s));

if (string.IsNullOrEmpty(options.ApiKey) == false)
authRequest.Headers["Api-Key"] = options.ApiKey;

return authRequest;
value.ConfigureRequest(this, new WebRequestEventArgs
{
Request = request
});
}

public void ConfigureRequest(RavenConnectionStringOptions options, WebRequest request)
public HttpRavenRequest Create(string url, string method, RavenConnectionStringOptions connectionStringOptions)
{
request.Credentials = options.Credentials ?? CredentialCache.DefaultNetworkCredentials;

if (RequestTimeoutInMs.HasValue)
request.Timeout = RequestTimeoutInMs.Value;

if (string.IsNullOrEmpty(options.CurrentOAuthToken) == false)
request.Headers["Authorization"] = options.CurrentOAuthToken;
return new HttpRavenRequest(url, method, ConfigureRequest, HandleUnauthorizedResponse, connectionStringOptions);
}

public HttpRavenRequest Create(string url, string method, RavenConnectionStringOptions connectionStringOptions)
private bool HandleUnauthorizedResponse(RavenConnectionStringOptions options, WebResponse webResponse)
{
return new HttpRavenRequest(url, method, ConfigureRequest, RefreshOauthToken, connectionStringOptions);
if (options.ApiKey == null)
return false;

var value = authenticators.GetOrAdd(options.ApiKey, s => new SecuredAuthenticator(s));

var oauthSource = options.Url + "/OAuth/API-Key";

var result = value.DoOAuthRequest(oauthSource);
return result != null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Raven.Client.Silverlight.Connection;
#endif

namespace Raven.Client.Connection
namespace Raven.Abstractions.Connection
{
/// <summary>
/// Event arguments for the event of creating a <see cref="WebRequest"/>
Expand Down
2 changes: 1 addition & 1 deletion Raven.Abstractions/Data/ApiKeyDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public string ConnectionString
if (string.IsNullOrWhiteSpace(Name) || string.IsNullOrWhiteSpace(Secret))
return null;

return string.Format(@"ApiKey = {0}, Database = {1}", FullApiKey, DbName);
return string.Format(@"ApiKey = {0}; Database = {1}", FullApiKey, DbName);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Raven.Abstractions/Data/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static Constants()
{
{"Text", "The encryption is correct."}
};
InDatabaseKeyVerificationDocumentContents.EnsureSnapshot();
InDatabaseKeyVerificationDocumentContents.EnsureCannotBeChangeAndEnableSnapshotting();
}

public const string RavenClientPrimaryServerUrl = "Raven-Client-Primary-Server-Url";
Expand Down
2 changes: 1 addition & 1 deletion Raven.Abstractions/Data/Facet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Facet
public List<string> Ranges { get; set; }
public int? MaxResults { get; set; }
public FacetTermSortMode TermSortMode { get; set; }
public bool InclueRemainingTerms { get; set; }
public bool IncludeRemainingTerms { get; set; }

public Facet()
{
Expand Down
Loading

0 comments on commit 00a379d

Please sign in to comment.