Beispiel #1
0
    def test_usr1_access_log(self, temp_dir):
        self.load('empty')

        log = 'access.log'
        log_new = 'new.log'
        log_path = temp_dir + '/' + log

        assert 'success' in self.conf('"' + log_path + '"',
                                      'access_log'), 'access log configure'

        assert waitforfiles(log_path), 'open'

        os.rename(log_path, temp_dir + '/' + log_new)

        assert self.get()['status'] == 200

        assert (self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "-" "-"',
                                     log_new) is not None), 'rename new'
        assert not os.path.isfile(log_path), 'rename old'

        with open(temp_dir + '/unit.pid', 'r') as f:
            pid = f.read().rstrip()

        call(['kill', '-s', 'USR1', pid])

        assert waitforfiles(log_path), 'reopen'

        assert self.get(url='/usr1')['status'] == 200

        unit_stop()

        assert (self.wait_for_record(r'"GET /usr1 HTTP/1.1" 200 0 "-" "-"',
                                     log) is not None), 'reopen 2'
        assert self.search_in_log(r'/usr1', log_new) is None, 'rename new 2'
Beispiel #2
0
    def test_node_application_promise_multiple_calls(self):
        self.load('promise_handler')

        self.post(
            headers={
                'Host': 'localhost',
                'Content-Type': 'text/html',
                'Connection': 'close',
            },
            body='callback1',
        )

        assert waitforfiles(self.temp_dir +
                            '/node/callback1'), 'promise first call'

        self.post(
            headers={
                'Host': 'localhost',
                'Content-Type': 'text/html',
                'Connection': 'close',
            },
            body='callback2',
        )

        assert waitforfiles(self.temp_dir +
                            '/node/callback2'), 'promise second call'
Beispiel #3
0
    def test_usr1_unit_log(self, temp_dir):
        self.load('log_body')

        log_new = 'new.log'
        log_path = temp_dir + '/unit.log'
        log_path_new = temp_dir + '/' + log_new

        os.rename(log_path, log_path_new)

        body = 'body_for_a_log_new'
        assert self.post(body=body)['status'] == 200

        assert self.wait_for_record(body, log_new) is not None, 'rename new'
        assert not os.path.isfile(log_path), 'rename old'

        with open(temp_dir + '/unit.pid', 'r') as f:
            pid = f.read().rstrip()

        call(['kill', '-s', 'USR1', pid])

        assert waitforfiles(log_path), 'reopen'

        body = 'body_for_a_log_unit'
        assert self.post(body=body)['status'] == 200

        unit_stop()

        assert self.wait_for_record(body) is not None, 'rename new'
        assert self.search_in_log(body, log_new) is None, 'rename new 2'

        # merge two log files into unit.log to check alerts

        with open(log_path, 'w') as unit_log, open(log_path_new,
                                                   'r') as unit_log_new:
            unit_log.write(unit_log_new.read())
Beispiel #4
0
    def test_node_application_promise_end(self):
        self.load('promise_end')

        assert (self.post(
            headers={
                'Host': 'localhost',
                'Content-Type': 'text/html',
                'Connection': 'close',
            },
            body='end',
        )['status'] == 200), 'promise end request'
        assert waitforfiles(self.temp_dir + '/node/callback'), 'promise end'
Beispiel #5
0
    def test_static_space_in_name(self, temp_dir):
        os.rename(
            temp_dir + '/assets/dir/file',
            temp_dir + '/assets/dir/fi le',
        )
        assert waitforfiles(temp_dir + '/assets/dir/fi le')
        assert self.get(url='/dir/fi le')['body'] == 'blah', 'file name'

        os.rename(temp_dir + '/assets/dir', temp_dir + '/assets/di r')
        assert waitforfiles(temp_dir + '/assets/di r/fi le')
        assert self.get(url='/di r/fi le')['body'] == 'blah', 'dir name'

        os.rename(temp_dir + '/assets/di r', temp_dir + '/assets/ di r ')
        assert waitforfiles(temp_dir + '/assets/ di r /fi le')
        assert (self.get(
            url='/ di r /fi le')['body'] == 'blah'), 'dir name enclosing'

        assert (self.get(
            url='/%20di%20r%20/fi le')['body'] == 'blah'), 'dir encoded'
        assert (self.get(
            url='/ di r %2Ffi le')['body'] == 'blah'), 'slash encoded'
        assert (self.get(
            url='/ di r /fi%20le')['body'] == 'blah'), 'file encoded'
        assert (self.get(
            url='/%20di%20r%20%2Ffi%20le')['body'] == 'blah'), 'encoded'
        assert (self.get(
            url='/%20%64%69%20%72%20%2F%66%69%20%6C%65')['body'] == 'blah'
                ), 'encoded 2'

        os.rename(
            temp_dir + '/assets/ di r /fi le',
            temp_dir + '/assets/ di r / fi le ',
        )
        assert waitforfiles(temp_dir + '/assets/ di r / fi le ')
        assert (self.get(url='/%20di%20r%20/%20fi%20le%20')['body'] == 'blah'
                ), 'file name enclosing'

        try:
            open(temp_dir + '/ф а', 'a').close()
            utf8 = True

        except:
            utf8 = False

        if utf8:
            os.rename(
                temp_dir + '/assets/ di r / fi le ',
                temp_dir + '/assets/ di r /фа йл',
            )
            assert waitforfiles(temp_dir + '/assets/ di r /фа йл')
            assert (self.get(
                url='/ di r /фа йл')['body'] == 'blah'), 'file name 2'

            os.rename(
                temp_dir + '/assets/ di r ',
                temp_dir + '/assets/ди ректория',
            )
            assert waitforfiles(temp_dir + '/assets/ди ректория/фа йл')
            assert (self.get(
                url='/ди ректория/фа йл')['body'] == 'blah'), 'dir name 2'
Beispiel #6
0
    def _run(self):
        build_dir = option.current_dir + '/build'
        self.unitd = build_dir + '/unitd'

        if not os.path.isfile(self.unitd):
            exit("Could not find unit")

        self.temp_dir = tempfile.mkdtemp(prefix='unit-test-')

        public_dir(self.temp_dir)

        if oct(stat.S_IMODE(os.stat(build_dir).st_mode)) != '0o777':
            public_dir(build_dir)

        os.mkdir(self.temp_dir + '/state')

        with open(self.temp_dir + '/unit.log', 'w') as log:
            self._p = subprocess.Popen(
                [
                    self.unitd,
                    '--no-daemon',
                    '--modules',
                    build_dir,
                    '--state',
                    self.temp_dir + '/state',
                    '--pid',
                    self.temp_dir + '/unit.pid',
                    '--log',
                    self.temp_dir + '/unit.log',
                    '--control',
                    'unix:' + self.temp_dir + '/control.unit.sock',
                    '--tmp',
                    self.temp_dir,
                ],
                stderr=log,
            )

        atexit.register(self.stop)

        if not waitforfiles(self.temp_dir + '/control.unit.sock'):
            _print_log(path=self.temp_dir + '/unit.log')
            exit("Could not start unit")

        self._started = True
Beispiel #7
0
    def test_node_application_write_callback(self):
        self.load('write_callback')

        assert self.get()['body'] == 'helloworld', 'write callback order'
        assert waitforfiles(self.temp_dir + '/node/callback'), 'write callback'