예제 #1
0
    def test_007(self):
        tmp = tempfile.mktemp(prefix='wave-testsuite-')
        subprocess.Popen("echo \"bar\"|../bin/mkpasswd -c {0} foo".format(tmp),
                         shell=True,
                         stdout=subprocess.PIPE).wait()
        yield app.set_auth(required=True, filename=tmp)
        yield auth.switch(tmp)

        c = MqttClient("auth:{seq}",
                       connect=False,
                       username="******",
                       password="******")
        ret = c.connect(version=4)
        # auth rejected
        if not isinstance(ret, EventConnack) or ret.ret_code == 0:
            debug(ret)
            defer.returnValue(False)

        # updating password
        subprocess.Popen("echo \"baz\"|../bin/mkpasswd {0} foo".format(tmp),
                         shell=True,
                         stdout=subprocess.PIPE).wait()
        # file is monitored each 2 secs in debug context
        time.sleep(3)

        ret = c.connect(version=4)
        # auth accepted
        if not isinstance(ret, EventConnack) or ret.ret_code != 0:
            debug(ret)
            defer.returnValue(False)

        defer.returnValue(True)
예제 #2
0
파일: 035_auth.py 프로젝트: gbour/wave
    def test_007(self):
        tmp = tempfile.mktemp(prefix='wave-testsuite-')
        subprocess.Popen("echo \"bar\"|../bin/mkpasswd -c {0} foo".format(tmp),
                         shell=True, stdout=subprocess.PIPE).wait()
        yield app.set_auth(required= True, filename= tmp)
        yield auth.switch(tmp)

        c = MqttClient("auth:{seq}", connect=False, username="******", password="******")
        ret = c.connect(version=4)
        # auth rejected
        if not isinstance(ret, EventConnack) or ret.ret_code == 0:
            debug(ret)
            defer.returnValue(False)

        # updating password
        subprocess.Popen("echo \"baz\"|../bin/mkpasswd {0} foo".format(tmp),
                         shell=True, stdout=subprocess.PIPE).wait()
        # file is monitored each 2 secs in debug context
        time.sleep(3)

        ret = c.connect(version=4)
        # auth accepted
        if not isinstance(ret, EventConnack) or ret.ret_code != 0:
            debug(ret)
            defer.returnValue(False)

        defer.returnValue(True)
예제 #3
0
파일: 035_auth.py 프로젝트: gbour/wave
    def test_002(self):
        yield app.set_auth(required=True)

        c = MqttClient("auth:{seq}", connect=False)
        ret = c.connect(version=4)
        if isinstance(ret, EventConnack) and ret.ret_code == 4:
            defer.returnValue(True)

        debug(ret)
        defer.returnValue(False)
예제 #4
0
    def test_002(self):
        yield app.set_auth(required=True)

        c = MqttClient("auth:{seq}", connect=False)
        ret = c.connect(version=4)
        if isinstance(ret, EventConnack) and ret.ret_code == 4:
            defer.returnValue(True)

        debug(ret)
        defer.returnValue(False)
예제 #5
0
파일: 035_auth.py 프로젝트: gbour/wave
    def test_003(self):
        tmp = tempfile.mktemp(prefix='wave-testsuite-')
        yield app.set_auth(required=True, filename=tmp); yield auth.switch(tmp)

        c = MqttClient("auth:{seq}", connect=False)
        ret = c.connect(version=4)
        if isinstance(ret, EventConnack) and ret.ret_code == 4:
            defer.returnValue(True)

        debug(ret)
        defer.returnValue(False)
예제 #6
0
    def test_003(self):
        tmp = tempfile.mktemp(prefix='wave-testsuite-')
        yield app.set_auth(required=True, filename=tmp)
        yield auth.switch(tmp)

        c = MqttClient("auth:{seq}", connect=False)
        ret = c.connect(version=4)
        if isinstance(ret, EventConnack) and ret.ret_code == 4:
            defer.returnValue(True)

        debug(ret)
        defer.returnValue(False)
예제 #7
0
    def test_008(self):
        tmp = tempfile.mktemp(prefix='wave-testsuite-')
        debug("pwd file: {0}".format(tmp))
        proc = subprocess.Popen(
            "echo \"bar\"|../bin/mkpasswd -c {0} foo".format(tmp),
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        (out, err) = proc.communicate()
        debug("out: {0}".format(out))
        debug("err: {0}".format(err))
        with open(tmp, 'r') as f:
            debug(f.read())

        yield app.set_auth(required=True, filename=tmp)
        yield auth.switch(tmp)

        c = MqttClient("auth:{seq}",
                       connect=False,
                       username="******",
                       password="******")
        ret = c.connect(version=4)
        # auth rejected
        if not isinstance(ret, EventConnack) or ret.ret_code != 0:
            debug(ret)
            defer.returnValue(False)
        c.disconnect()

        # deleting password
        proc = subprocess.Popen(
            "../bin/mkpasswd -D {0} foo && touch {0}".format(tmp),
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        (out, err) = proc.communicate()
        debug("out: {0}".format(out))
        debug("err: {0}".format(err))
        with open(tmp, 'r') as f:
            debug(f.read())

        # file is monitored each 2 secs in debug context
        #time.sleep(5)
        yield auth.switch(tmp)

        ret = c.connect(version=4)
        # auth accepted
        if not isinstance(ret, EventConnack) or ret.ret_code != 4:
            debug(ret)
            defer.returnValue(False)

        defer.returnValue(True)
예제 #8
0
파일: 035_auth.py 프로젝트: gbour/wave
    def test_005(self):
        tmp = tempfile.mktemp(prefix='wave-testsuite-')
        subprocess.Popen("echo \"bar\"|../bin/mkpasswd -c {0} foo".format(tmp),
                         shell=True, stdout=subprocess.PIPE).wait()
        yield app.set_auth(required= True, filename= tmp)
        yield auth.switch(tmp)

        c = MqttClient("auth:{seq}", connect=False, username="******", password="******")
        ret = c.connect(version=4)
        # auth rejected
        if isinstance(ret, EventConnack) and ret.ret_code == 4:
            defer.returnValue(True)

        debug(ret)
        defer.returnValue(False)
예제 #9
0
    def test_005(self):
        tmp = tempfile.mktemp(prefix='wave-testsuite-')
        subprocess.Popen("echo \"bar\"|../bin/mkpasswd -c {0} foo".format(tmp),
                         shell=True,
                         stdout=subprocess.PIPE).wait()
        yield app.set_auth(required=True, filename=tmp)
        yield auth.switch(tmp)

        c = MqttClient("auth:{seq}",
                       connect=False,
                       username="******",
                       password="******")
        ret = c.connect(version=4)
        # auth rejected
        if isinstance(ret, EventConnack) and ret.ret_code == 4:
            defer.returnValue(True)

        debug(ret)
        defer.returnValue(False)
예제 #10
0
파일: 035_auth.py 프로젝트: gbour/wave
    def test_008(self):
        tmp = tempfile.mktemp(prefix='wave-testsuite-')
        debug("pwd file: {0}".format(tmp))
        proc = subprocess.Popen("echo \"bar\"|../bin/mkpasswd -c {0} foo".format(tmp),
                         shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        (out,err) = proc.communicate()
        debug("out: {0}".format(out)); debug("err: {0}".format(err))
        with open(tmp, 'r') as f:
            debug(f.read())

        yield app.set_auth(required= True, filename= tmp)
        yield auth.switch(tmp)

        c = MqttClient("auth:{seq}", connect=False, username="******", password="******")
        ret = c.connect(version=4)
        # auth rejected
        if not isinstance(ret, EventConnack) or ret.ret_code != 0:
            debug(ret)
            defer.returnValue(False)
        c.disconnect()


        # deleting password
        proc = subprocess.Popen("../bin/mkpasswd -D {0} foo && touch {0}".format(tmp),
                         shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        (out,err) = proc.communicate()
        debug("out: {0}".format(out)); debug("err: {0}".format(err))
        with open(tmp, 'r') as f:
            debug(f.read())

        # file is monitored each 2 secs in debug context
        #time.sleep(5)
        yield auth.switch(tmp)

        ret = c.connect(version=4)
        # auth accepted
        if not isinstance(ret, EventConnack) or ret.ret_code != 4:
            debug(ret)
            defer.returnValue(False)

        defer.returnValue(True)
예제 #11
0
파일: 035_auth.py 프로젝트: gbour/wave
 def cleanup_suite(self):
     # set back default values (required = false) so following tests are working :)
     yield app.set_auth(required=False)
예제 #12
0
    def setup_suite(self):
        ## configuring auth
        (fd, auth_file) = tempfile.mkstemp(prefix='wave-auth-')
        os.close(fd)
        print "auth file:", auth_file
        with open(auth_file, 'w') as f:
            f.write(
                """ctrl:$2a$12$4xhMVs/zgy6T/GZobBAdc.bpbL2yaXnckX5YE9z5abEnGzsSaIeGq
foo:$2a$12$EwUNtApVj6j2z9VQlMf98O8Xc.650HdRFK6Rr4sVG6bc/tdjjgXOW
""")
        yield app.set_auth(required=True, filename=auth_file)
        yield auth.switch(auth_file)

        ## configuring acls
        (fd, acl_file) = tempfile.mkstemp(prefix='wave-acl-')
        os.close(fd)
        print "acl file:", acl_file

        with open(acl_file, 'w') as f:
            f.write("""
# testsuite acl file
ctrl\tallow\tr\ttest/#

anonymous\tallow\tr\ttest/anonymous/sub/1
anonymous\tallow\tr\ttest/anonymous/sub/2/+
anonymous\tallow\tw\ttest/anonymous/pub/1
anonymous\tallow\tw\ttest/anonymous/pub/2/#

foo\tallow\tr\ttest/foo/sub/1
foo\tallow\tr\ttest/foo/sub/2/+
foo\tallow\tw\ttest/foo/pub/1
foo\tallow\tw\ttest/foo/pub/2/#
""")

        users = {
            'anonymous': {
                'user': None,
                'password': None
            },
            'foo': {
                'user': '******',
                'password': '******'
            },
        }

        i = 1
        for user in sorted(users.keys()):

            @defer.inlineCallbacks
            def _init1(self):
                yield app.set_acl(enabled=False)

                defer.returnValue(
                    self._t_check(client=user, acl=False, **users[user]))

            setattr(
                self, "test_{0:03}".format(i),
                types.MethodType(
                    catch(desc("user '{0}', no acl".format(user))(_init1)),
                    self))

            i += 1

            @defer.inlineCallbacks
            def _init2(self):
                yield app.set_acl(enabled=True, filename=acl_file)
                yield acl.switch(acl_file)

                defer.returnValue(
                    self._t_check(client=user, acl=True, **users[user]))

            setattr(
                self, "test_{0:03}".format(i),
                types.MethodType(
                    catch(
                        desc("user '{0}', acls enabled".format(user))(_init2)),
                    self))

            i += 1
예제 #13
0
 def cleanup_suite(self):
     yield app.set_auth(required=False)
     yield app.set_acl(enabled=False)
예제 #14
0
 def cleanup_suite(self):
     # set back default values (required = false) so following tests are working :)
     yield app.set_auth(required=False)
예제 #15
0
파일: 036_acl.py 프로젝트: gbour/wave
 def cleanup_suite(self):
     yield app.set_auth(required=False)
     yield app.set_acl(enabled=False)
예제 #16
0
파일: 036_acl.py 프로젝트: gbour/wave
    def setup_suite(self):
        ## configuring auth
        (fd, auth_file) = tempfile.mkstemp(prefix='wave-auth-'); os.close(fd)
        print "auth file:", auth_file
        with open(auth_file, 'w') as f:
            f.write(
"""ctrl:$2a$12$4xhMVs/zgy6T/GZobBAdc.bpbL2yaXnckX5YE9z5abEnGzsSaIeGq
foo:$2a$12$EwUNtApVj6j2z9VQlMf98O8Xc.650HdRFK6Rr4sVG6bc/tdjjgXOW
""")
        yield app.set_auth(required=True, filename=auth_file)
        yield auth.switch(auth_file)

        ## configuring acls
        (fd, acl_file) = tempfile.mkstemp(prefix='wave-acl-'); os.close(fd)
        print "acl file:", acl_file

        with open(acl_file, 'w') as f:
            f.write("""
# testsuite acl file
ctrl\tallow\tr\ttest/#

anonymous\tallow\tr\ttest/anonymous/sub/1
anonymous\tallow\tr\ttest/anonymous/sub/2/+
anonymous\tallow\tw\ttest/anonymous/pub/1
anonymous\tallow\tw\ttest/anonymous/pub/2/#

foo\tallow\tr\ttest/foo/sub/1
foo\tallow\tr\ttest/foo/sub/2/+
foo\tallow\tw\ttest/foo/pub/1
foo\tallow\tw\ttest/foo/pub/2/#
""")

        users = {
            'anonymous': {'user': None , 'password': None},
            'foo':       {'user': '******', 'password': '******'},
        }



        i = 1
        for user in sorted(users.keys()):
            @defer.inlineCallbacks
            def _init1(self):
                yield app.set_acl(enabled=False)

                defer.returnValue(self._t_check(client=user, acl=False, **users[user]))
            setattr(self, "test_{0:03}".format(i), types.MethodType(catch(desc(
                "user '{0}', no acl".format(user))(
                _init1)), self))

            i += 1
            @defer.inlineCallbacks
            def _init2(self):
                yield app.set_acl(enabled=True, filename=acl_file); yield acl.switch(acl_file)

                defer.returnValue(self._t_check(client=user, acl=True, **users[user]))
            setattr(self, "test_{0:03}".format(i), types.MethodType(catch(desc(
                "user '{0}', acls enabled".format(user))(
                _init2)), self))

            i += 1