public UserServiceTest() { _passwordHash = A.Fake <IPasswordHashService>(); _userRepositoryService = A.Fake <IUserRepositoryService>(); _jwtService = A.Fake <IJsonWebTokenService>(); _httpRequestParser = A.Fake <IHttpRequestParser>(); _emailService = A.Fake <IEmailService>(); _factorAuthenticatorManager = A.Fake <ITwoFactorAuthenticatorManager>(); _loginAttemptRepoService = A.Fake <ILoginAttemptsRepositoryService>(); _refreshTokenRepositoryService = A.Fake <IRefreshTokenRepositoryService>(); _whiteListRepostirotyService = A.Fake <IWhitelistedIpRepositoryService>(); _userService = new UserService ( _userRepositoryService, _passwordHash, _jwtService, _httpRequestParser, _emailService, _factorAuthenticatorManager, _whiteListRepostirotyService, _loginAttemptRepoService, _refreshTokenRepositoryService ); }
/// <summary> /// Initializes a new instance of the <see cref="HttpClientContext"/> class. /// </summary> /// <param name="secured">true if the connection is secured (SSL/TLS)</param> /// <param name="remoteEndPoint">client that connected.</param> /// <param name="stream">Stream used for communication</param> /// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param> /// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 4096 bytes.</param> /// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception> /// <exception cref="ArgumentException">Stream must be writable and readable.</exception> public HttpClientContext(bool secured, IPEndPoint remoteEndPoint, Stream stream, IRequestParserFactory parserFactory, int bufferSize, Socket sock, ILogWriter log) { Check.Require(remoteEndPoint, "remoteEndPoint"); Check.NotEmpty(remoteEndPoint.Address.ToString(), "remoteEndPoint.Address"); Check.Require(stream, "stream"); Check.Require(parserFactory, "parser"); Check.Min(4096, bufferSize, "bufferSize"); Check.Require(sock, "socket"); if (!stream.CanWrite || !stream.CanRead) throw new ArgumentException("Stream must be writable and readable."); _bufferSize = bufferSize; RemoteAddress = remoteEndPoint.Address.ToString(); RemotePort = remoteEndPoint.Port.ToString(); _log = log; _parser = parserFactory.CreateParser(_log); _parser.RequestCompleted += OnRequestCompleted; _parser.RequestLineReceived += OnRequestLine; _parser.HeaderReceived += OnHeaderReceived; _parser.BodyBytesReceived += OnBodyBytesReceived; _currentRequest = new HttpRequest(); IsSecured = secured; if (stream == null) throw new NullReferenceException ("Null Stream in HttpClientContext"); _stream = stream; _buffer = new byte[bufferSize]; }
/// <summary> /// Initializes a new instance of the <see cref="HttpClientContext"/> class. /// </summary> /// <param name="secured">true if the connection is secured (SSL/TLS)</param> /// <param name="remoteEndPoint">client that connected.</param> /// <param name="stream">Stream used for communication</param> /// <param name="clientCertificate">Client security certificate</param> /// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param> /// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 4096 bytes.</param> /// <param name="socket">Client socket</param> /// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception> /// <exception cref="ArgumentException">Stream must be writable and readable.</exception> public HttpClientContext(bool secured, IPEndPoint remoteEndPoint, Stream stream, ClientCertificate clientCertificate, IRequestParserFactory parserFactory, int bufferSize, Socket socket) { Check.Require(remoteEndPoint, "remoteEndPoint"); Check.NotEmpty(remoteEndPoint.Address.ToString(), "remoteEndPoint.Address"); Check.Require(stream, "stream"); Check.Require(parserFactory, "parser"); Check.Min(4096, bufferSize, "bufferSize"); Check.Require(socket, "socket"); if (!stream.CanWrite || !stream.CanRead) throw new ArgumentException("Stream must be writable and readable."); _bufferSize = bufferSize; RemoteAddress = remoteEndPoint.Address.ToString(); RemotePort = remoteEndPoint.Port.ToString(); _log = NullLogWriter.Instance; _parser = parserFactory.CreateParser(_log); _parser.RequestCompleted += OnRequestCompleted; _parser.RequestLineReceived += OnRequestLine; _parser.HeaderReceived += OnHeaderReceived; _parser.BodyBytesReceived += OnBodyBytesReceived; _localEndPoint = (IPEndPoint)socket.LocalEndPoint; HttpRequest request = new HttpRequest(); request._remoteEndPoint = remoteEndPoint; request.Secure = secured; _currentRequest = request; IsSecured = secured; _stream = stream; _clientCertificate = clientCertificate; _buffer = new byte[bufferSize]; }
/// <summary> /// Initializes a new instance of the <see cref="HttpClientContext"/> class. /// </summary> /// <param name="secured">true if the connection is secured (SSL/TLS)</param> /// <param name="remoteEndPoint">client that connected.</param> /// <param name="stream">Stream used for communication</param> /// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param> /// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 1024 bytes.</param> /// <param name="sock">Socket to use.</param> /// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception> /// <exception cref="ArgumentException">Stream must be writable and readable.</exception> public HttpClientContext( bool secured, IPEndPoint remoteEndPoint, Stream stream, IRequestParserFactory parserFactory, int bufferSize, Socket sock) { Check.Require(remoteEndPoint, "remoteEndPoint"); Check.NotEmpty(remoteEndPoint.Address.ToString(), "remoteEndPoint.Address"); Check.Require(stream, "stream"); Check.Require(parserFactory, "parser"); Check.Min(1024, bufferSize, "bufferSize"); Check.Require(sock, "socket"); if (!stream.CanWrite || !stream.CanRead) { throw new ArgumentException("Stream must be writable and readable."); } _bufferSize = bufferSize; RemoteAddress = remoteEndPoint.Address.ToString(); RemotePort = remoteEndPoint.Port.ToString(); _log = NullLogWriter.Instance; _parser = parserFactory.CreateParser(_log); _parser.RequestCompleted += OnRequestCompleted; _parser.RequestLineReceived += OnRequestLine; _parser.HeaderReceived += OnHeaderReceived; _parser.BodyBytesReceived += OnBodyBytesReceived; _currentRequest = new HttpRequest(); IsSecured = secured; _stream = stream; _buffer = new byte[bufferSize]; }
public GraphQLAzureFunctionsMiddlewareProxy( IRequestExecutorResolver graphQLExecutorResolver, IHttpResultSerializer graphQLResultSerializer, IHttpRequestParser graphQLRequestParser, NameString schemaName = default, GraphQLAzureFunctionsConfigOptions options = null ) { //We support multiple schemas by allowing a name to be specified, but default to DefaultName if not. this.SchemaName = schemaName.HasValue ? schemaName : Schema.DefaultName; //Initialize the Server Options with defaults! this.Options = options ?? new GraphQLAzureFunctionsConfigOptions(); //Validate Dependencies... this.ExecutorResolver = graphQLExecutorResolver ?? throw new ArgumentNullException(nameof(graphQLExecutorResolver), GRAPHQL_MIDDLEWARE_INIT_ERROR); this.ResultSerializer = graphQLResultSerializer ?? throw new ArgumentNullException(nameof(graphQLResultSerializer), GRAPHQL_MIDDLEWARE_INIT_ERROR); this.RequestParser = graphQLRequestParser ?? throw new ArgumentNullException(nameof(graphQLRequestParser), GRAPHQL_MIDDLEWARE_INIT_ERROR); //The File Provider is initialized internally as an EmbeddedFileProvider this.FileProvider = GraphQLInitHelpers.CreateEmbeddedFileProvider(); //Set the RoutePath; a dependency of all dynamic file serving Middleware! this.RoutePath = new PathString(Options.AzureFunctionsRoutePath); //Initialize the Primary Middleware (POST) as needed for references to GetExecutorAsync() for Error Handling, etc.... //NOTE: This will also return the Middleware to be used as the primary reference. this.PrimaryMiddleware = ConfigureMiddlewareChainOfResponsibility(); }
public HttpMultipartMiddleware( HttpRequestDelegate next, IRequestExecutorResolver executorResolver, IHttpResultSerializer resultSerializer, IHttpRequestParser requestParser, NameString schemaName) : base(next, executorResolver, resultSerializer, requestParser, schemaName) { }
/// <summary> /// Initializes a new instance of the <see cref="HttpClientContext"/> class. /// </summary> /// <param name="secured">true if the connection is secured (SSL/TLS)</param> /// <param name="remoteEndPoint">client that connected.</param> /// <param name="stream">Stream used for communication</param> /// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param> /// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 4096 bytes.</param> /// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception> /// <exception cref="ArgumentException">Stream must be writable and readable.</exception> public HttpClientContext(bool secured, IPEndPoint remoteEndPoint, Stream stream, IRequestParserFactory parserFactory, Socket sock) { Check.Require(remoteEndPoint, "remoteEndPoint"); Check.NotEmpty(remoteEndPoint.Address.ToString(), "remoteEndPoint.Address"); Check.Require(stream, "stream"); Check.Require(parserFactory, "parser"); Check.Require(sock, "socket"); if (!stream.CanWrite || !stream.CanRead) { throw new ArgumentException("Stream must be writable and readable."); } RemoteAddress = remoteEndPoint.Address.ToString(); RemotePort = remoteEndPoint.Port.ToString(); _log = NullLogWriter.Instance; m_parser = parserFactory.CreateParser(_log); m_parser.RequestCompleted += OnRequestCompleted; m_parser.RequestLineReceived += OnRequestLine; m_parser.HeaderReceived += OnHeaderReceived; m_parser.BodyBytesReceived += OnBodyBytesReceived; m_currentRequest = new HttpRequest(this); IsSecured = secured; _stream = stream; m_sock = sock; m_bufferSize = 8196; m_ReceiveBuffer = new byte[m_bufferSize]; requestsInServiceIDs = new HashSet <uint>(); SSLCommonName = ""; if (secured) { SslStream _ssl = (SslStream)_stream; X509Certificate _cert1 = _ssl.RemoteCertificate; if (_cert1 != null) { X509Certificate2 _cert2 = new X509Certificate2(_cert1); if (_cert2 != null) { SSLCommonName = _cert2.GetNameInfo(X509NameType.SimpleName, false); } } } ++basecontextID; if (basecontextID <= 0) { basecontextID = 1; } contextID = basecontextID; }
public HttpPostMiddleware( HttpRequestDelegate next, IRequestExecutorResolver executorResolver, IHttpResultSerializer resultSerializer, IHttpRequestParser requestParser, NameString schemaName) : base(next, executorResolver, resultSerializer, schemaName) { _requestParser = requestParser ?? throw new ArgumentNullException(nameof(requestParser)); }
public HttpMultipartMiddleware( HttpRequestDelegate next, IRequestExecutorResolver executorResolver, IHttpResultSerializer resultSerializer, IHttpRequestParser requestParser, NameString schemaName, IOptions <FormOptions> formOptions) : base(next, executorResolver, resultSerializer, requestParser, schemaName) { _formOptions = formOptions.Value; }
public GraphQLAzureFunctionsExecutorProxyV11( IRequestExecutorResolver graphqlExecutorResolver, IHttpResultSerializer graphqlResultSerializer, IHttpRequestParser graphqlRequestParser, NameString schemaName = default ) { this.AzureFunctionsMiddlewareProxy = new GraphQLAzureFunctionsMiddlewareProxy( graphqlExecutorResolver, graphqlResultSerializer, graphqlRequestParser, schemaName ); }
public HttpGetMiddleware( HttpRequestDelegate next, IRequestExecutorResolver executorResolver, IHttpResultSerializer resultSerializer, IHttpRequestParser requestParser, IServerDiagnosticEvents diagnosticEvents, NameString schemaName) : base(next, executorResolver, resultSerializer, schemaName) { _requestParser = requestParser ?? throw new ArgumentNullException(nameof(requestParser)); _diagnosticEvents = diagnosticEvents ?? throw new ArgumentNullException(nameof(diagnosticEvents)); }
public CsgoFastApi ( CsgoFastApiConfiguration configuration, ISteamMarketScraperService steamMarketScraperService, IHttpRequestParser httpRequestParser, IMongoPricingRepository pricingRepository, ILogger <CsgoFastApi> logger ) { _configuration = configuration; _steamMarketScraperService = steamMarketScraperService; _httpRequestParser = httpRequestParser; _pricingRepository = pricingRepository; _logger = logger; }
/// <summary> /// Initializes a new instance of the <see cref="HttpClientContext"/> class. /// </summary> /// <param name="secured">true if the connection is secured (SSL/TLS)</param> /// <param name="remoteEndPoint">client that connected.</param> /// <param name="stream">Stream used for communication</param> /// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param> /// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 4096 bytes.</param> /// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception> /// <exception cref="ArgumentException">Stream must be writable and readable.</exception> public HttpClientContext(bool secured, IPEndPoint remoteEndPoint, Stream stream, ILogWriter m_logWriter, Socket sock) { if (!stream.CanWrite || !stream.CanRead) { throw new ArgumentException("Stream must be writable and readable."); } LocalIPEndPoint = remoteEndPoint; m_log = m_logWriter; m_isClosing = false; m_parser = new HttpRequestParser(m_log); m_parser.RequestCompleted += OnRequestCompleted; m_parser.RequestLineReceived += OnRequestLine; m_parser.HeaderReceived += OnHeaderReceived; m_parser.BodyBytesReceived += OnBodyBytesReceived; m_currentRequest = new HttpRequest(this); IsSecured = secured; m_stream = stream; m_sock = sock; m_ReceiveBuffer = new byte[16384]; m_requests = new Queue <HttpRequest>(); SSLCommonName = ""; if (secured) { SslStream _ssl = (SslStream)m_stream; X509Certificate _cert1 = _ssl.RemoteCertificate; if (_cert1 != null) { X509Certificate2 _cert2 = new X509Certificate2(_cert1); if (_cert2 != null) { SSLCommonName = _cert2.GetNameInfo(X509NameType.SimpleName, false); } } } ++basecontextID; if (basecontextID <= 0) { basecontextID = 1; } contextID = basecontextID; sock.NoDelay = true; }
public HttpPostMiddleware( HttpRequestDelegate next, IRequestExecutorResolver executorResolver, IHttpResultSerializer resultSerializer, IHttpRequestParser requestParser, IServerDiagnosticEvents diagnosticEvents, NameString schemaName) : base( next, executorResolver, resultSerializer, requestParser, diagnosticEvents, schemaName) { }
public GraphQLAzureFunctionsExecutorProxyV11Plus( IRequestExecutorResolver graphQLExecutorResolver, IHttpResultSerializer graphQLResultSerializer, IHttpRequestParser graphQLRequestParser, NameString schemaName = default, GraphQLAzureFunctionsConfigOptions options = null ) { this.AzureFunctionsMiddlewareProxy = new GraphQLAzureFunctionsMiddlewareProxy( graphQLExecutorResolver, graphQLResultSerializer, graphQLRequestParser, schemaName, options ); }
/// <summary> /// Initializes a new instance of the <see cref="HttpClientContext"/> class. /// </summary> /// <param name="secured">true if the connection is secured (SSL/TLS)</param> /// <param name="remoteEndPoint">client that connected.</param> /// <param name="stream">Stream used for communication</param> /// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param> /// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 4096 bytes.</param> /// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception> /// <exception cref="ArgumentException">Stream must be writable and readable.</exception> public HttpClientContext(bool secured, IPEndPoint remoteEndPoint, Stream stream, IRequestParserFactory parserFactory, int bufferSize, Socket sock) { Check.Require(remoteEndPoint, "remoteEndPoint"); Check.NotEmpty(remoteEndPoint.Address.ToString(), "remoteEndPoint.Address"); Check.Require(stream, "stream"); Check.Require(parserFactory, "parser"); Check.Min(4096, bufferSize, "bufferSize"); Check.Require(sock, "socket"); if (!stream.CanWrite || !stream.CanRead) { throw new ArgumentException("Stream must be writable and readable."); } _bufferSize = bufferSize; RemoteAddress = remoteEndPoint.Address.ToString(); RemotePort = remoteEndPoint.Port.ToString(); _log = NullLogWriter.Instance; _parser = parserFactory.CreateParser(_log); _parser.RequestCompleted += OnRequestCompleted; _parser.RequestLineReceived += OnRequestLine; _parser.HeaderReceived += OnHeaderReceived; _parser.BodyBytesReceived += OnBodyBytesReceived; _currentRequest = new HttpRequest(); IsSecured = secured; _stream = stream; _buffer = new byte[bufferSize]; // by Fumi.Iseki SSLCommonName = ""; if (secured) { SslStream _ssl = (SslStream)_stream; X509Certificate _cert1 = _ssl.RemoteCertificate; if (_cert1 != null) { X509Certificate2 _cert2 = new X509Certificate2(_cert1); if (_cert2 != null) { SSLCommonName = _cert2.GetNameInfo(X509NameType.SimpleName, false); } } } }
/// <summary> /// Constructor. /// </summary> /// <param name="url">Url which is hosts this message source.</param> /// <param name="httpRequestParser">HTTP request parser.</param> /// <param name="routeBuilder">Route builder.</param> /// <param name="servicesBuilder">Services builder.</param> /// <param name="loggingBuilder">Logging builder.</param> internal HttpMessageSource(string url, IHttpRequestParser <TMessage> httpRequestParser = null, Action <IRouteBuilder> routeBuilder = null, Action <IServiceCollection> servicesBuilder = null, Action <ILoggingBuilder> loggingBuilder = null) { if (string.IsNullOrEmpty(url)) { throw new ArgumentException("Url is required.", nameof(url)); } Url = url; _httpRequestParser = httpRequestParser ?? new HttpRequestJsonParser <TMessage>(); _loggingBuilder = loggingBuilder ?? ConfigureDefaultLogging; _routeBuilder = routeBuilder ?? ConfigureDefaultRouting; _servicesBuilder = servicesBuilder ?? ConfigureDefaultServices; }
public GraphQLAzureFunctionsMiddlewareProxy( IRequestExecutorResolver graphqlExecutorResolver, IHttpResultSerializer graphqlResultSerializer, IHttpRequestParser graphqlRequestParser, NameString schemaName = default ) { //We support multiple schemas by allowing a name to be specified, but default to DefaultName if not. this.SchemaName = schemaName.HasValue ? schemaName : Schema.DefaultName; //Validate Dependencies... this.ExecutorResolver = graphqlExecutorResolver ?? throw new ArgumentNullException(nameof(graphqlExecutorResolver), GRAPHQL_MIDDLEWARE_INIT_ERROR); this.ResultSerializer = graphqlResultSerializer ?? throw new ArgumentNullException(nameof(graphqlResultSerializer), GRAPHQL_MIDDLEWARE_INIT_ERROR); this.RequestParser = graphqlRequestParser ?? throw new ArgumentNullException(nameof(graphqlRequestParser), GRAPHQL_MIDDLEWARE_INIT_ERROR); //BBernard - Initialize the middleware proxy and pipeline with support for both Http GET & POST processing... //NOTE: Middleware uses the Pipeline Pattern (similar to Chain Of Responsibility), therefore // we adapt that here to manually build up the two key middleware handlers for Http Get & Http Post processing. var httpGetMiddlewareShim = new HttpGetMiddleware( (httpContext) => throw new HttpRequestException( "GraphQL was unable to process the request, ensure that an Http POST or GET GraphQL request was sent as well-formed Json." ), this.ExecutorResolver, this.ResultSerializer, this.RequestParser, this.SchemaName ); ////NOTE: The normal use case for GraphQL is POST'ing of the query so we initialize it last in the chain/pipeline //// so that it is the first to execute, and then fallback to Http Get if appropriate, finally throw //// an exception if neither are supported by the current request. this.MiddlewareProxy = new HttpPostMiddleware( async(httpContext) => await httpGetMiddlewareShim.InvokeAsync(httpContext), this.ExecutorResolver, this.ResultSerializer, this.RequestParser, this.SchemaName ); }
public UserService ( IUserRepositoryService userRepositoryService, IPasswordHashService passwordHashService, IJsonWebTokenService jwtService, IHttpRequestParser httpRequestParser, IEmailService emailService, ITwoFactorAuthenticatorManager factorAuthenticatorManager, IWhitelistedIpRepositoryService whitelistedIpRepositoryService, ILoginAttemptsRepositoryService loginAttemptsRepositoryService, IRefreshTokenRepositoryService refreshTokenRepositoryService ) { _userRepositoryService = userRepositoryService; _passwordHashService = passwordHashService; _jwtService = jwtService; _httpRequestParser = httpRequestParser; _emailService = emailService; _factorAuthenticatorManager = factorAuthenticatorManager; _whitelistedIpRepositoryService = whitelistedIpRepositoryService; _loginAttemptsRepositoryService = loginAttemptsRepositoryService; _refreshTokenRepositoryService = refreshTokenRepositoryService; }
public HttpServiceHandler(IHttpRequestParser requestParser, IRouteHandler routeHandler) { this.requestParser = requestParser; this.routeHandler = routeHandler; }
/// <summary> /// Use HTTP request parser. /// </summary> /// <param name="httpRequestParser">HTTP request parser.</param> /// <returns>HttpMessageSourceBuilder.</returns> public HttpMessageSourceBuilder <TMessage> UseHttpRequestParser(IHttpRequestParser <TMessage> httpRequestParser) { _httpRequestParser = httpRequestParser ?? throw new ArgumentNullException(nameof(httpRequestParser)); return(this); }