Example #1
0
    def test_bad_config(self):
        self.mox.StubOutWithMock(config, 'build_settings')
        settings = """
[something]
this_does_not_matter=nope
        """.strip()        
        config.build_settings().AndReturn(create_settings(settings))
        self.mox.ReplayAll()
        self.assertRaises(NappingCatBadConfig, serve.ServeApp.run)
Example #2
0
    def test_raises_importerror_on_bad_router(self):
        self.mox.StubOutWithMock(config, 'build_settings')
        settings = """
[%s]
routers=dne.dne.dne
        """.strip() % config.SECTION_NAME
        config.build_settings().AndReturn(create_settings(settings))
        self.mox.ReplayAll()

        # this time we care that things are broken.
        self.assertRaises(ImportError, serve.ServeApp.run)
Example #3
0
    def test_inserts_into_sys_path(self):
        self.mox.StubOutWithMock(config, 'build_settings')
        random_paths = ['rand-%d' for i in range(0,3)]
        settings = """
[%s]
paths = 
    %s
    %s
    %s
        """.strip() % (config.SECTION_NAME, random_paths[0], random_paths[1], random_paths[2]) 
        config.build_settings().AndReturn(create_settings(settings))
        self.mox.ReplayAll()


        # we don't really care about this assertion.
        serve.ServeApp(
            environ={'argv':[random.randint(1,100)]},
        ).setup_environ()

        self.assertTrue(all([path in sys.path for path in random_paths]))
Example #4
0
    def setup_environ(self):
        settings = config.build_settings()        
        if not settings.has_section(config.SECTION_NAME):
            raise exceptions.NappingCatBadConfig("""
                Your nappingcat.conf file does not include a %s section!
            """.strip() % config.SECTION_NAME)

        kitty_config = config.setup_environ(settings)

        self.global_settings = settings
        self.nappingcat_settings = kitty_config
Example #5
0
    def test_reads_from_appropriate_path_and_file(self):
        f = open(self.filename, 'w')
        print >>f,"""
[kittyconfig]
blah=3
        """.strip()
        f.flush()
        f.close()

        self.mox.StubOutWithMock(os.path, 'expanduser')
        os.path.expanduser(mox.IsA(str)).AndReturn(self.filename)
        self.mox.ReplayAll()
        results = config.build_settings()
        self.assertTrue(isinstance(results, ConfigParser.ConfigParser))
        self.mox.VerifyAll()
Example #6
0
    def test_delegates_properly(self):
        self.mox.StubOutWithMock(config, 'build_settings')
        settings = """
[%s]
routers=tests.serve
auth=tests.gittests.test_utils.AllAuth
        """.strip() % config.SECTION_NAME
        config.build_settings().AndReturn(create_settings(settings))
        config.build_settings().AndReturn(create_settings(settings))
        config.build_settings().AndReturn(create_settings(settings))
        self.mox.ReplayAll()


        random_user = '******' % random.randint(1,100)
        app = serve.ServeApp(
            environ={'SSH_ORIGINAL_COMMAND':SIMPLE_COMMAND, 'user':random_user},
            stdin=random.randint(1,100),
            stdout=random.randint(1,100),
            stderr=random.randint(1,100)
        )
        app.setup_environ()
        args, kwargs = app.main()
        
        self.assertTrue(isinstance(args[0], request.Request))
        self.assertEqual(args[0].command, SIMPLE_COMMAND)

        app = serve.ServeApp(
            environ={'SSH_ORIGINAL_COMMAND':'hey there'},
            stdin=random.randint(1,100),
            stdout=random.randint(1,100),
            stderr=random.randint(1,100)
        )
        app.setup_environ()
        args, kwargs = app.main()
        
        self.assertTrue(isinstance(args[0], request.Request))
        self.assertEqual(args[0].command, 'hey there')
        self.assertTrue('something' in kwargs)
        self.assertEqual(kwargs['something'], 'there')
        self.assertEqual(kwargs['optional'], None)
        
        app = serve.ServeApp(
            environ={'SSH_ORIGINAL_COMMAND':'hey there girl'},
            stdin=random.randint(1,100),
            stdout=random.randint(1,100),
            stderr=random.randint(1,100)
        )
        app.setup_environ()
        args, kwargs = app.main()
        self.assertTrue(isinstance(args[0], request.Request))
        self.assertEqual(args[0].command, 'hey there girl')
        self.assertTrue('something' in kwargs)
        self.assertEqual(kwargs['something'], 'there')
        self.assertEqual(kwargs['optional'], 'girl')
def main(name=None, key=None):
    name = sys.argv[1] if name is None else name
    key = sys.stdin.read() if key is None else key
    settings = build_settings()
    auth = get_auth_backend_from_settings(settings)
    pubkey_handler = dict(settings.items(SECTION_NAME)).get('public_key_handler', 'nappingcat.pubkey_handlers.AuthorizedKeysFile')
    pubkey_handler = import_class_from_module(pubkey_handler)()

    auth.add_user(name)
    auth.add_key_to_user(name, key)
    auth.add_permission(
        name,
        ('auth', 'adduser'),
    )
    auth.add_permission(
        name,
        ('auth', 'modifyuser'),
    )
    auth.finish(pubkey_handler)
    print "\033[0;32m%s\033[0m\n" % """
    You just created a super great super user!
    """.strip()