def test_forward_root(self):
     resp = Conn().get("/", req_hdrs={"Host": "not-example.com"})
     status, hdrs, body = parse(resp)
     self.assertContains(status, "301 Moved Permanently")
     expect = "http://catchall.example.com/"
     self.assertEquals(hdrs["Location"], expect)
     self.assertContains(body, expect)
Example #2
0
 def test_forward_root(self):
     resp = self.get('/', req_hdrs={'Host': 'not-example.com'})
     status, hdrs, body = parse(resp)
     self.assertContains(status, "301 Moved Permanently")
     expect = "http://catchall.example.com/"
     self.assertEqual(hdrs["Location"], expect)
     self.assertContains(body, expect)
Example #3
0
 def test_forward_relative(self):
     resp = self.get('/foo/bar', req_hdrs={'Host': 'secure.example.com'})
     status, hdrs, body = parse(resp)
     self.assertContains(status, "301 Moved Permanently")
     expect = "https://www.example.com/secure/foo/bar"
     self.assertEqual(hdrs["Location"], expect)
     self.assertContains(body, expect)
Example #4
0
 def test_no_redirect(self):
     resp = self.get(
         '/',
         req_hdrs={
             'Host': 'example.com',
             'X-Forwarded-Proto': 'https',  # Already https.
         })
     status, hdrs, body = parse(resp)
     self.assertContains(status, '200 OK')
 def get_helper(self, idx):
     fn, content_type = self.files[idx]
     resp = Conn().get("/" + fn)
     status, hdrs, body = parse(resp)
     self.assertContains(status, "200 OK")
     self.assertEquals(hdrs["Accept-Ranges"], "bytes")
     self.assertEquals(hdrs["Content-Length"], str(self.datalen))
     self.assertEquals(hdrs["Content-Type"], content_type)
     self.assertContains(hdrs["Server"], "darkhttpd/")
     self.assertEquals(body, self.data)
Example #6
0
 def test_https_redirect(self):
     resp = self.get('/foo/bar',
                     req_hdrs={
                         'Host': 'example.com',
                         'X-Forwarded-Proto': 'http',
                     })
     status, hdrs, body = parse(resp)
     self.assertContains(status, '301 Moved Permanently')
     expect = 'https://example.com/foo/bar'
     self.assertEqual(hdrs['Location'], expect)
     self.assertContains(body, expect)
Example #7
0
 def test_wrong_auth(self):
     resp = self.get(
         self.url,
         req_hdrs={
             'Authorization':
             'Basic ' +
             base64.b64encode(b'myuser:wrongpass').decode('utf-8')
         })
     status, hdrs, body = parse(resp)
     self.assertContains(status, '401 Unauthorized')
     self.assertEqual(hdrs['WWW-Authenticate'],
                      'Basic realm="User Visible Realm"')
     self.assertContains(hdrs['Server'], 'darkhttpd/')
Example #8
0
 def test_with_auth(self):
     resp = self.get(self.url,
                     req_hdrs={
                         'Authorization':
                         'Basic ' + base64.b64encode('myuser:mypass')
                     })
     status, hdrs, body = parse(resp)
     self.assertContains(status, '200 OK')
     self.assertEquals(hdrs["Accept-Ranges"], "bytes")
     self.assertEquals(hdrs["Content-Length"], str(self.datalen))
     self.assertEquals(hdrs["Content-Type"], "image/jpeg")
     self.assertContains(hdrs["Server"], "darkhttpd/")
     assert body == self.data, [url, resp, status, hdrs, body]
     self.assertEquals(body, self.data)
Example #9
0
from pprint import pprint
import cparser, test

testcode = """
#include <stdio.h>

int main(int argc, char** argv) {
	printf("Hello %s\n", "world");
	printf("args: %i\n", argc);
	int i;
	for(i = 0; i < argc; ++i)
		printf("%s\n", argv[i]);
}
"""

state = test.parse(testcode, withGlobalIncludeWrappers=True)

import interpreter
interpreter = interpreter.Interpreter()
interpreter.register(state)
interpreter.registerFinalize()


def dump():
    for f in state.contentlist:
        if not isinstance(f, cparser.CFunc): continue
        if not f.body: continue

        print
        print "parsed content of " + str(f) + ":"
        for c in f.body.contentlist:
Example #10
0
 def test_no_server_id(self):
     resp = self.get('/', method='BOGUS')
     status, hdrs, body = parse(resp)
     self.assertContains(status, "400 Bad Request")
     self.assertFalse('Server' in hdrs)
     self.assertFalse(b'Generated by darkhttpd/' in body)
Example #11
0
 def test_no_listing(self):
     resp = self.get("/")
     status, hdrs, body = parse(resp)
     self.assertContains(status, "404 Not Found")
Example #12
0
from pprint import pprint
from cparser import *
import test

testcode = """
	int16_t (*f)();
	int16_t (*g)(char a, void*);
	int (*h);
	
	// ISO/IEC 9899:TC3 : C99 standard
	int fx(void), *fip(), (*pfi)(); // example 1, page 120
	int (*apfi[3])(int *x, int *y); // example 2, page 120
	int (*fpfi(int (*)(long), int))(int, ...); // example 3, page 120
"""

state = test.parse(testcode)	

f = state.vars["f"]
g = state.vars["g"]

assert f.name == "f"
assert isinstance(f.type, CFuncPointerDecl)
assert f.type.type == CStdIntType("int16_t")
assert f.type.args == []

assert isinstance(g.type, CFuncPointerDecl)
gargs = g.type.args
assert isinstance(gargs, list)
assert len(gargs) == 2
assert isinstance(gargs[0], CFuncArgDecl)
assert gargs[0].name == "a"
Example #13
0
 def test_no_auth(self):
     resp = self.get(self.url)
     status, hdrs, body = parse(resp)
     self.assertContains(status, '401 Unauthorized')
     self.assertEquals(hdrs['WWW-Authenticate'],
                       'Basic realm="User Visible Realm"')
from pprint import pprint
import cparser, test

testcode = """
#include <stdio.h>

int main(int argc, char** argv) {
	printf("Hello %s\n", "world");
	printf("args: %i\n", argc);
	int i;
	for(i = 0; i < argc; ++i)
		printf("%s\n", argv[i]);
}
"""

state = test.parse(testcode, withGlobalIncludeWrappers=True)


import interpreter
interpreter = interpreter.Interpreter()
interpreter.register(state)
interpreter.registerFinalize()

def dump():
	for f in state.contentlist:
		if not isinstance(f, cparser.CFunc): continue
		if not f.body: continue
		
		print
		print "parsed content of " + str(f) + ":"
		for c in f.body.contentlist:
Example #15
0
 def test_without_header(self):
     resp = self.get('/', req_hdrs={'Host': 'example.com'})
     status, hdrs, body = parse(resp)
     self.assertContains(status, '200 OK')
Example #16
0
from pprint import pprint
from cparser import *
import test

testcode = """
	int16_t (*f)();
	int16_t (*g)(char a, void*);
	int (*h);
	
	// ISO/IEC 9899:TC3 : C99 standard
	int fx(void), *fip(), (*pfi)(); // example 1, page 120
	int (*apfi[3])(int *x, int *y); // example 2, page 120
	int (*fpfi(int (*)(long), int))(int, ...); // example 3, page 120
"""

state = test.parse(testcode)

f = state.vars["f"]
g = state.vars["g"]

assert f.name == "f"
assert isinstance(f.type, CFuncPointerDecl)
assert f.type.type == CStdIntType("int16_t")
assert f.type.args == []

assert isinstance(g.type, CFuncPointerDecl)
gargs = g.type.args
assert isinstance(gargs, list)
assert len(gargs) == 2
assert isinstance(gargs[0], CFuncArgDecl)
assert gargs[0].name == "a"
 def test_no_server_id(self):
     resp = Conn().get("/", method='BOGUS')
     status, hdrs, body = parse(resp)
     self.assertContains(status, "400 Bad Request")
     self.assertFalse(hdrs.has_key("Server"))
     self.assertFalse("Generated by darkhttpd/" in body)