public void ToString_UserAndPassSupplied_ReturnsUserPassBase64Encoded() { const string EXPECTED = "dXNlcjpwYXNz"; var credentials = new HttpBasicAuthCredentials("user", "pass"); Assert.That(credentials.ToString(), Is.StringMatching(EXPECTED)); }
public void Ctor_UserNameAndPasswordSpecified_SetsBasicAuthenticationHeader() { var config = new ClientConfiguration("test") { Username = "******", Password = "******" }; var client = new MockHttpClient <object>(HttpStatusCode.OK); new HttpChannel(config, client); var header = client.Headers["Authorization"]; var credentials = new HttpBasicAuthCredentials("user", "pass").ToString(); Assert.That(header, Is.StringContaining("Basic " + credentials)); }
public override bool ShouldAcceptConnection(HttpRequest connectionRequest, HttpResponse connectionResponse) { HttpBasicAuthCredentials credentials = connectionRequest.BasicAuthCredentials; User user = NibriServer.AccountManager.GetByName(credentials != null ? credentials.Username : null); if (user == null || !user.CheckPassword(credentials != null ? credentials.Password : null)) { // Authentication failed! connectionResponse.RequireHttpBasicAuthentication("Nibriboard"); connectionResponse.ContentType = "text/plain"; connectionResponse.SetBody("Error: Invalid username or password."); return(false); } // TODO: Origin checking here // Authentication suceeded :D return(true); }