コード例 #1
0
        public void Cant_Process(string getRequest)
        {
            var mockFileSearch = new MockFileProcessor()
                                 .StubExists(true);
            var properties = new ServerProperties(@"c:/",
                                                  5555, new ServerTime(),
                                                  new MockPrinter(),
                                                  new Readers
            {
                DirectoryProcess = new MockDirectoryProcessor(),
                FileProcess      = mockFileSearch
            });
            var inlinePdfService = new InlinePdfService();

            Assert.False(inlinePdfService
                         .CanProcessRequest(getRequest, properties));
        }
コード例 #2
0
        public void Cant_Send_Data_Protected_Data()
        {
            var zSocket        = new MockZSocket();
            var mockFileSearch = new MockFileProcessor()
                                 .StubExists(true);
            var properties = new ServerProperties(@"c:/",
                                                  5555, new ServerTime(),
                                                  new MockPrinter(),
                                                  new Readers
            {
                DirectoryProcess = new MockDirectoryProcessor(),
                FileProcess      = mockFileSearch
            });
            var fileSendService = new FileSendService();
            var correctOutput   = new StringBuilder();

            correctOutput.Append(@"<!DOCTYPE html>");
            correctOutput.Append(@"<html>");
            correctOutput.Append(@"<head><title>Vatic Server 403 Error Page</title></head>");
            correctOutput.Append(@"<body>");
            correctOutput.Append(@"<h1>403 Forbidden, Can not process request on port 5555</h1>");
            correctOutput.Append(@"</body>");
            correctOutput.Append(@"</html>");
            var statusCode
                = fileSendService
                  .ProcessRequest("GET /pagefile.sys HTTP/1.1",
                                  new HttpResponse(zSocket),
                                  properties);

            Assert.Equal("403 Forbidden", statusCode);
            zSocket.VerifySend(GetByte("HTTP/1.1 403 Forbidden\r\n"),
                               GetByteCount("HTTP/1.1 403 Forbidden\r\n"));
            zSocket.VerifySend(GetByte("Cache-Control: no-cache\r\n"),
                               GetByteCount("Cache-Control: no-cache\r\n"));
            zSocket.VerifySend(GetByte("Content-Type: text/html\r\n"),
                               GetByteCount("Content-Type: text/html\r\n"));
            zSocket.VerifySend(GetByte("Content-Length: "
                                       + GetByteCount(correctOutput.ToString())
                                       + "\r\n\r\n"),
                               GetByteCount("Content-Length: "
                                            + GetByteCount(correctOutput.ToString())
                                            + "\r\n\r\n"));

            zSocket.VerifySend(GetByte(correctOutput.ToString()),
                               GetByteCount(correctOutput.ToString()));
        }
コード例 #3
0
        public void Cant_Process(string getRequest)
        {
            var mockFileSearch = new MockFileProcessor()
                                 .StubExists(true);
            var properties = new ServerProperties(@"c:/",
                                                  5555, new ServerTime(),
                                                  new MockPrinter(),
                                                  new Readers()
            {
                DirectoryProcess = new DirectoryProcessor(),
                FileProcess      = mockFileSearch
            });
            var videoStream = new VideoStreamingService();

            Assert.False(videoStream.CanProcessRequest(getRequest,
                                                       properties));
        }
コード例 #4
0
        public void Get_Video_Page()
        {
            var zSocket = new MockZSocket();
            var guid    = Guid.NewGuid();
            var data    = new byte[1024];

            data[0] = 0;
            data[1] = 1;
            var writeStream = File.Open("c:/" + guid + ".mp4",
                                        FileMode.OpenOrCreate, FileAccess.ReadWrite,
                                        FileShare.Read);

            writeStream.Write(data, 0, 2);
            writeStream.Close();

            var mockFileSearch = new MockFileProcessor()
                                 .StubExists(true)
                                 .StubFileSize(2);

            var properties = new ServerProperties(@"c:/",
                                                  5555, new ServerTime(),
                                                  new MockPrinter(),
                                                  new Readers()
            {
                DirectoryProcess = new DirectoryProcessor(),
                FileProcess      = mockFileSearch
            });
            var videoStream = new VideoStreamingService();

            var statusCode = videoStream
                             .ProcessRequest("GET /" + guid + ".mp4 HTTP/1.1",
                                             new HttpResponse(zSocket), properties);
            var correctOutput = new StringBuilder();

            correctOutput.Append(@"<!DOCTYPE html>");
            correctOutput.Append(@"<html>");
            correctOutput.Append(@"<head><title>Vatic Video</title></head>");
            correctOutput.Append(@"<body>");
            correctOutput.Append(@"<video width=""320"" height=""240"" controls>");
            correctOutput.Append(@"<source src=""http://127.0.0.1:5555/" + guid + ".mp4.vaticToMp4");
            correctOutput.Append(@""" type=""video/mp4"">");
            correctOutput.Append(@"</video>");
            correctOutput.Append(@"</body>");
            correctOutput.Append(@"</html>");

            File.Delete("c:/" + guid + ".mp4");
            Assert.Equal("200 OK", statusCode);
            zSocket.VerifySend(GetByte("HTTP/1.1 200 OK\r\n"),
                               GetByteCount("HTTP/1.1 200 OK\r\n"));
            zSocket.VerifySend(GetByte("Cache-Control: no-cache\r\n"),
                               GetByteCount("Cache-Control: no-cache\r\n"));
            zSocket.VerifySend(GetByte("Content-Type: text/html\r\n"),
                               GetByteCount("Content-Type: text/html\r\n"));
            zSocket.VerifySend(GetByte("Content-Length: "
                                       + GetByteCount(correctOutput.ToString())
                                       + "\r\n\r\n"),
                               GetByteCount("Content-Length: "
                                            + GetByteCount(correctOutput.ToString())
                                            + "\r\n\r\n"));

            zSocket.VerifySend(GetByte(correctOutput.ToString()),
                               GetByteCount(correctOutput.ToString()));
        }
コード例 #5
0
        public void Send_Data_Post_Request()
        {
            var zSocket        = new MockZSocket();
            var mockFileSearch = new MockFileProcessor()
                                 .StubExists(true);
            var properties = new ServerProperties(@"c:/",
                                                  5555, new ServerTime(),
                                                  new MockPrinter(),
                                                  new Readers
            {
                DirectoryProcess = new DirectoryProcessor(),
                FileProcess      = mockFileSearch
            });
            var formService = new FormService();

            var statusCode = formService.ProcessRequest("POST /form HTTP/1.1\r\n" +
                                                        "Host: localhost:8080\r\n" +
                                                        "Connection: keep-alive\r\n" +
                                                        "Content-Length: 33\r\n" +
                                                        "Cache - Control: max - age = 0\r\n" +
                                                        "Accept: text / html,application / xhtml + xml,application / xml; q = 0.9,image / webp,*/*;q=0.8\r\n" +
                                                        "Origin: http://localhost:8080\r\n" +
                                                        "Upgrade-Insecure-Requests: 1\r\n" +
                                                        "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36\r\n" +
                                                        "Content-Type: application/x-www-form-urlencoded\r\n" +
                                                        "Referer: http://localhost:8080/form\r\n" +
                                                        "Accept-Encoding: gzip, deflate\r\n" +
                                                        "Accept-Language: en-US,en;q=0.8\r\n\r\n" +
                                                        "firstname=John%26"
                                                        + "&lastname=Walsher%26",
                                                        new HttpResponse(zSocket), properties);

            var correctOutput = new StringBuilder();

            correctOutput.Append(@"<!DOCTYPE html>");
            correctOutput.Append(@"<html>");
            correctOutput.Append(@"<head><title>Vatic Form Page</title></head>");
            correctOutput.Append(@"<body>");

            correctOutput.Append(@"First Name Submitted:<br>");
            correctOutput.Append(@"John&amp;<br>");
            correctOutput.Append(@"Last Name Submitted:<br>");
            correctOutput.Append(@"Walsher&amp;<br>");


            correctOutput.Append(@"</body>");
            correctOutput.Append(@"</html>");

            Assert.Equal("200 OK", statusCode);
            zSocket.VerifySend(GetByte("HTTP/1.1 200 OK\r\n"),
                               GetByteCount("HTTP/1.1 200 OK\r\n"));
            zSocket.VerifySend(GetByte("Cache-Control: no-cache\r\n"),
                               GetByteCount("Cache-Control: no-cache\r\n"));
            zSocket.VerifySend(GetByte("Content-Type: text/html\r\n"),
                               GetByteCount("Content-Type: text/html\r\n"));
            zSocket.VerifySend(GetByte("Content-Length: "
                                       + GetByteCount(correctOutput.ToString())
                                       + "\r\n\r\n"),
                               GetByteCount("Content-Length: "
                                            + GetByteCount(correctOutput.ToString())
                                            + "\r\n\r\n"));
            zSocket.VerifySend(GetByte(correctOutput.ToString()),
                               GetByteCount(correctOutput.ToString()));
            zSocket.VerifySend(GetByte(correctOutput.ToString()),
                               GetByteCount(correctOutput.ToString()));
        }