def test_get_rules(self, mock_request):
        fix_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data/get_rules.json')
        with open(fix_path) as fd:
            fix = json.load(fd)

        mock_request.return_value = fix
        config = {'client_id': 'AAAA', 'client_secret': 'BBBB', 'uri': 'localhost'}
        az = AuthZero(config)

        ret = az.get_rules()
        assert(isinstance(ret, list))
        assert(len(ret)) == 2
        assert(isinstance(ret[0], dict))
        assert(ret[0].get('id') is not None)
        assert(ret[0].get('script') is not None)
        assert(ret[0].get('enabled') is True)
Beispiel #2
0
    args = parser.parse_args()

    config = DotDict({
        'client_id': args.clientid,
        'client_secret': args.clientsecret,
        'uri': args.uri
    })
    authzero = AuthZero(config)
    authzero.get_access_token()
    logger.debug("Got access token for client_id:{}".format(args.clientid))
    dry_run_message = 'Dry Run : Action not taken : ' if args.dry_run else ''

    # on any error, `authzero` will raise an exception and python will exit with non-zero code

    # Remote rules loader
    remote_rules = authzero.get_rules()
    logger.debug("Loaded {} remote rules from current Auth0 deployment".format(
        len(remote_rules)))

    # Local rules loader
    if not os.path.isdir(args.rules_dir):
        raise Exception('NotARulesDirectory' (args.rules_dir))

    # Process all local rules
    local_rules_files = glob.glob("{}/*.json".format(args.rules_dir))
    local_rules = []
    for rfile in local_rules_files:
        logger.debug("Reading local rule configuration {}".format(rfile))
        rule = AuthZeroRule()
        # Overload the object with our own statuses
        rule.is_new = False