public virtual Authenticate AuthenticateToServer(UserConfiguration config)
 {
     var tmp = new Authenticate(config.ServerUrl, config.User, config.Password);
     _handshake = tmp;
     _container.Register<Handshake>().To(_handshake);
     return tmp;
 }
        public void AuthenticatePingTest()
        {
            var xml = new XElement("root",
                          new XElement("auth", "token"),
                          new XElement("version", 1),
                          new XElement("update", "1900-01-01"),
                          new XElement("add", "1900-01-02"),
                          new XElement("clean", "1900-01-03"),
                          new XElement("songs", "1234"),
                          new XElement("albums", "123"),
                          new XElement("artists", "12"),
                          new XElement("tags", "10"),
                          new XElement("videos", "1"));
            var stream = new System.IO.MemoryStream();
            xml.Save(stream);
            stream.Position = 0;
            var mockResponse = Substitute.For<WebResponse>();
            mockResponse.GetResponseStream().Returns(stream);
            _mockRequest = Substitute.For<WebRequest>();
            _mockRequest.GetResponse().Returns(mockResponse);
            var password = "******";
            var user = "******";
            var server = "authenticate://test";

            var res = new Authenticate(server, user, password);
            _uri = null;
            res.Ping();
            Assert.That(_uri, Is.Not.Null);
            Assert.That(_uri, Is.EqualTo(string.Format("{0}/server/xml.server.php?action=ping&auth={1}", server, "token")));
        }
 public virtual Authenticate AuthenticationTest(string server, string user, string password)
 {
     var tmp = new Authenticate(server, user, password);
     return tmp;
 }
        public void AuthenticateSuccessTest()
        {
            var xml = new XElement("root",
                          new XElement("auth", "token"),
                          new XElement("version", 1),
                          new XElement("update", "1900-01-01"),
                          new XElement("add", "1900-01-02"),
                          new XElement("clean", "1900-01-03"),
                          new XElement("songs", "1234"),
                          new XElement("albums", "123"),
                          new XElement("artists", "12"),
                          new XElement("tags", "10"),
                          new XElement("videos", "1"));
            var stream = new System.IO.MemoryStream();
            xml.Save(stream);
            stream.Position = 0;
            var mockResponse = Substitute.For<WebResponse>();
            mockResponse.GetResponseStream().Returns(stream);
            _mockRequest = Substitute.For<WebRequest>();
            _mockRequest.GetResponse().Returns(mockResponse);
            var password = "******";
            var user = "******";
            var server = "authenticate://test";

            byte[] passBytes = Encoding.UTF8.GetBytes(password);
            var hasher = new SHA256Managed();
            var tmpBytes = hasher.ComputeHash(passBytes);
            var now = DateTime.Now.UnixEpoch();
            var hashword = HexString(tmpBytes);
            tmpBytes = Encoding.UTF8.GetBytes(now + hashword);
            tmpBytes = hasher.ComputeHash(tmpBytes);
            var passphrase = HexString(tmpBytes);

            var res = new Authenticate(server, user, password);
            Assert.That(_uri, Is.Not.Null);
            Assert.That(_uri, Is.EqualTo(string.Format("{0}/server/xml.server.php?action=handshake&auth={1}&timestamp={2}&version=350001&user={3}", server, passphrase, now, user)));
            Assert.That(res.AlbumCount, Is.EqualTo(123));
            Assert.That(res.SongCount, Is.EqualTo(1234));
            Assert.That(res.ArtistCount, Is.EqualTo(12));
            Assert.That(res.User, Is.EqualTo(user));
            Assert.That(res.Server, Is.EqualTo(server));
            Assert.That(res.Passphrase, Is.EqualTo("token")); // from auth xml node above
        }
 public void AuthenticateNoUserNameTest()
 {
     var test = new Authenticate("test", null, "test");
     Assert.Fail();
 }
 public void AuthenticateNoPasswordTest()
 {
     var test = new Authenticate("test", "test", null);
     Assert.Fail();
 }