예제 #1
0
        public void TestRule()
        {
            Either <Error, Tuple <string, RuleBuilder> > res =
                Parser.Rule("right(#authority, $resource, #read) <- resource( #ambient, $resource), operation(#ambient, #read)");

            Assert.AreEqual(new Right(new Tuple <string, RuleBuilder>("",
                                                                      Utils.Rule("right",
                                                                                 Arrays.AsList(Utils.Symbol("authority"), Utils.Var("resource"), Utils.Symbol("read")),
                                                                                 Arrays.AsList(
                                                                                     Utils.Pred("resource", Arrays.AsList(Utils.Symbol("ambient"), Utils.Var("resource"))),
                                                                                     Utils.Pred("operation", Arrays.AsList(Utils.Symbol("ambient"), Utils.Symbol("read"))))
                                                                                 ))),
                            res);
        }
예제 #2
0
        public void TestRuleWithExpressionOrdering()
        {
            Either <Error, Tuple <string, RuleBuilder> > res =
                Parser.Rule("valid_date(\"file1\") <- time(#ambient, $0 ), $0 <= 2019-12-04T09:46:41+00:00, resource( #ambient, \"file1\")");

            Assert.AreEqual(new Right(new Tuple <string, RuleBuilder>("",
                                                                      Utils.ConstrainedRule("valid_date",
                                                                                            Arrays.AsList(Utils.Strings("file1")),
                                                                                            Arrays.AsList(
                                                                                                Utils.Pred("time", Arrays.AsList(Utils.Symbol("ambient"), Utils.Var("0"))),
                                                                                                Utils.Pred("resource", Arrays.AsList(Utils.Symbol("ambient"), Utils.Strings("file1")))
                                                                                                ),
                                                                                            Arrays.AsList <ExpressionBuilder>(
                                                                                                new ExpressionBuilder.Binary(
                                                                                                    ExpressionBuilder.Op.LessOrEqual,
                                                                                                    new ExpressionBuilder.Value(Utils.Var("0")),
                                                                                                    new ExpressionBuilder.Value(new Term.Date(1575452801)))
                                                                                                )
                                                                                            ))),
                            res);
        }