Ejemplo n.º 1
0
 def test_direct_proxy(self):
     proxy = pac4cli["-F", "DIRECT", "-p", "23128"] & BG
     sleep(3)
     try:
         with plumbum.local.env(http_proxy="localhost:23128"):
             curl("http://www.booking.com")
             self.assertTrue(True)
     finally:
         proxy.proc.kill()
Ejemplo n.º 2
0
    def test_proxy_from_dhcp_wpad(self):
        # set up mock dbus with dhcp settings
        wifi1 = self.dbusmock.AddWiFiDevice('mock_WiFi1', 'wlan0',
                                            DeviceState.ACTIVATED)
        ap1 = self.dbusmock.AddAccessPoint(
            wifi1, 'Mock_AP1', 'The_SSID', '00:23:F8:7E:12:BB',
            InfrastructureMode.NM_802_11_MODE_INFRA, 2425, 5400, 82,
            NM80211ApSecurityFlags.NM_802_11_AP_SEC_KEY_MGMT_PSK)
        con1 = self.dbusmock.AddWiFiConnection(wifi1, 'Mock_Con1', 'The_SSID', '')
        active_con1 = self.dbusmock.AddActiveConnection(
            [wifi1], con1, ap1, 'Mock_Active1',
            NMActiveConnectionState.NM_ACTIVE_CONNECTION_STATE_ACTIVATED)

        self.dbusmock.AddObject(
            '/org/freedesktop/NetworkManager/DHCP4Config/1',
            'org.freedesktop.NetworkManager.DHCP4Config',
            {
                'Options': {
                    'wpad': 'http://localhost:8080/wpad.dat',
                },
            },
            [],
        )
        conn_obj = dbus.Interface(
            self.dbus_con.get_object("org.freedesktop.NetworkManager", active_con1),
            dbusmock.MOCK_IFACE,
        )
        conn_obj.AddProperty(
            'org.freedesktop.NetworkManager.Connection.Active',
            'Dhcp4Config',
            '/org/freedesktop/NetworkManager/DHCP4Config/1',
        )

        # for inspecting the resulting dbus objects
        # with plumbum.local.env(DBUS_SYSTEM_BUS_ADDRESS=os.environ['DBUS_SYSTEM_BUS_ADDRESS']):
        #    gdbus["introspect", "--system", "--recurse", "-d", "org.freedesktop.NetworkManager", "-o", "/"] & FG

        # server for wpad.dat
        with plumbum.local.cwd(testdir / "wpadserver"):
            static_server = python["-m", "http.server", 8080] & BG

        # mock upstream proxies
        fake_proxy_1 = (serve_once[23130] < testdir / "fake-proxy-1-response") & BG
        fake_proxy_2 = (serve_once[23131] < testdir / "fake-proxy-2-response") & BG

        # proxy getting its config from DHCP
        with plumbum.local.env(DBUS_SYSTEM_BUS_ADDRESS=os.environ['DBUS_SYSTEM_BUS_ADDRESS']):
            proxy_to_test = pac4cli["-p", "23129"] & BG(stdout=sys.stdout, stderr=sys.stderr)

        sleep(3)
        try:
            with plumbum.local.env(http_proxy="localhost:23129"):
                self.assertEqual(
                    curl("http://www.booking.com"),
                    # when changing this string, don't forget to change
                    # the Content-Length header as well.
                    "Hello from fake proxy no 1!",
                )
                self.assertEqual(
                    curl("http://www.google.com"),
                    # (same)
                    "Hello from fake proxy no 2!",
                )
        finally:
            proxy_to_test.proc.kill()
            fake_proxy_2.proc.kill()
            fake_proxy_1.proc.kill()
            static_server.proc.kill()
Ejemplo n.º 3
0
  def __repr__(self):
    return 'Class({},"{}")'.format(self.hours,self.tag)
  def __hash__(self):
    return str(self).__hash__()
  def __eq__(self,other):
    return str(self) == str(other)
  def __gt__(self,other):
    return self.tag.split()[1] > other.tag.split()[1]

def course_representer(dumper, data):
  return dumper.represent_scalar('!course',str(data))

yaml.add_representer(Class, course_representer)

# parse
for url,text in ({link:getter(link) for element, attribute, link, pos in lxml.html.document_fromstring(curl('http://www.catalog.gatech.edu/colleges/coc/ugrad/comsci/threads.php')).iterlinks() if re.search(r'/threads/degreq/.*[^2]\.php$',link)}).items():
  text = text.split('\nBachelor of Science in Computer Science THREAD: ')[1].lstrip().split('\n  TOTAL:   ')[0]
  lines = text.splitlines()
  assert len(lines)
  name = lines[0].upper()
  pair = name.split(' & ')
  threads |= set(pair)
  threadpairs.add(frozenset(pair))
  columns = lines[4]
  #pprint.pprint(lines[5])
  format = lambda line: ('{:<'+str(len(columns))+'}').format(line)
  columns_pattern = re.sub(r' (\.+)',lambda match: ' ({})'.format(match.group(1)),re.sub(r'-','.',columns))
  requirements = map(lambda line: map(lambda col:col.strip() or '--',re.match(columns_pattern,format(line)).groups()), filter(lambda s: s.startswith('  '),lines[5:]))
  threadpairclasses[frozenset(pair)] = frozenset(Class(req[1],req[2]) for req in map(list,requirements))
  #(echo[name+'\n'+pprint.pformat(threadpairclasses[frozenset(pair)])] | less) & plumbum.FG
Ejemplo n.º 4
0
    def __gt__(self, other):
        return self.tag.split()[1] > other.tag.split()[1]


def course_representer(dumper, data):
    return dumper.represent_scalar('!course', str(data))


yaml.add_representer(Class, course_representer)

# parse
for url, text in ({
        link: getter(link)
        for element, attribute, link, pos in lxml.html.document_fromstring(
            curl(
                'http://www.catalog.gatech.edu/colleges/coc/ugrad/comsci/threads.php'
            )).iterlinks() if re.search(r'/threads/degreq/.*[^2]\.php$', link)
}).items():
    text = text.split('\nBachelor of Science in Computer Science THREAD: '
                      )[1].lstrip().split('\n  TOTAL:   ')[0]
    lines = text.splitlines()
    assert len(lines)
    name = lines[0].upper()
    pair = name.split(' & ')
    threads |= set(pair)
    threadpairs.add(frozenset(pair))
    columns = lines[4]
    #pprint.pprint(lines[5])
    format = lambda line: ('{:<' + str(len(columns)) + '}').format(line)
    columns_pattern = re.sub(r' (\.+)',
                             lambda match: ' ({})'.format(match.group(1)),