Coverage report for Casbin.Parser.AST.
Generated at 18/02/2019 12:10:19 by DelphiCodeCoverage - an open source tool for Delphi Code Coverage.
Statistics for Casbin.Parser.AST.pas
| Number of lines covered | 42 |
| Number of lines with code gen | 43 |
| Line coverage | 97% |
| 1 | // Copyright 2018 by John Kouraklis and Contributors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | unit Casbin.Parser.AST; |
| 15 | |
| 16 | interface |
| 17 | |
| 18 | uses |
| 19 | Casbin.Parser.AST.Types; |
| 20 | |
| 21 | procedure addAssertion(const aHeader: THeaderNode; const aLine: string); |
| 22 | |
| 23 | implementation |
| 24 | |
| 25 | uses |
| 26 | System.SysUtils, Casbin.Model.Sections.Types, System.Classes, |
| 27 | System.StrUtils, Casbin.Effect.Types; |
| 28 | |
| 29 | procedure addAssertion(const aHeader: THeaderNode; const aLine: string); |
| 30 | var |
| 31 | child: TChildNode; //PALOFF |
| 32 | assertion: TAssertionNode; //PALOFF |
| 33 | effect: TEffectNode; //PALOFF |
| 34 | index: Integer; |
| 35 | sep: Char; |
| 36 | key: string; |
| 37 | objStr: string; |
| 38 | strList: TstringList; |
| 39 | value: string; |
| 40 | begin |
| 41 | if not Assigned(aHeader) then |
| 42 | raise Exception.Create('Header is nil'); |
| 43 | |
| 44 | sep:='='; |
| 45 | if (aHeader.SectionType=stPolicyRules) or |
| 46 | (aHeader.SectionType=stRoleRules) then |
| 47 | sep:=','; |
| 48 | |
| 49 | index:=Pos(sep, aLine, Low(string)); |
| 50 | if index=0 then |
| 51 | Exit; |
| 52 | |
| 53 | key:=Copy(aLine, Low(string), index-1); |
| 54 | value:=Copy(aLine, index+1, Length(aLine)); |
| 55 | |
| 56 | case aHeader.SectionType of |
| 57 | stMatchers, |
| 58 | stDefault, |
| 59 | stRoleDefinition, |
| 60 | stUnknown: begin |
| 61 | child:=TChildNode.Create; //PALOFF |
| 62 | child.Key:=key; |
| 63 | child.Value:=value; |
| 64 | aHeader.ChildNodes.Add(child); |
| 65 | end; |
| 66 | |
| 67 | stRequestDefinition, |
| 68 | stPolicyDefinition, |
| 69 | stPolicyRules, |
| 70 | stRoleRules: begin |
| 71 | strList:=TstringList.Create; |
| 72 | try |
| 73 | strList.Delimiter:=','; |
| 74 | strList.DelimitedText:=value; |
| 75 | strList.StrictDelimiter:=True; |
| 76 | |
| 77 | child:=TChildNode.Create; //PALOFF |
| 78 | child.Key:=key; |
| 79 | child.Value:=value; |
| 80 | aHeader.ChildNodes.Add(child); |
| 81 | for objStr in strList do |
| 82 | begin |
| 83 | assertion:=TAssertionNode.Create; //PALOFF |
| 84 | assertion.Key:=key; |
| 85 | assertion.Value:=objStr; |
| 86 | child.AssertionList.Add(assertion); |
| 87 | end; |
| 88 | finally |
| 89 | strList.Free; |
| 90 | end; |
| 91 | end; |
| 92 | |
| 93 | stPolicyEffect: begin |
| 94 | effect:=TEffectNode.Create; //PALOFF |
| 95 | effect.Key:=key; |
| 96 | effect.Value:=value; |
| 97 | |
| 98 | value:=ReplaceStr(value, '_', '.'); |
| 99 | case IndexStr(UpperCase(value), |
| 100 | [UpperCase(effectConditions[0]), |
| 101 | UpperCase(effectConditions[1]), |
| 102 | UpperCase(effectConditions[2]), |
| 103 | UpperCase(effectConditions[3]), |
| 104 | UpperCase(effectConditions[4]), |
| 105 | UpperCase(effectConditions[5]), |
| 106 | UpperCase(effectConditions[6]), |
| 107 | UpperCase(effectConditions[7])]) of |
| 108 | 0, 1: effect.EffectCondition:=ecSomeAllow; |
| 109 | 2, 3: effect.EffectCondition:=ecNotSomeDeny; |
| 110 | 4, 5: effect.EffectCondition:=ecSomeAllowANDNotDeny; |
| 111 | 6, 7: effect.EffectCondition:=ecPriorityORDeny; |
| 112 | else |
| 113 | effect.EffectCondition:=ecUnknown; |
| 114 | end; |
| 115 | aHeader.ChildNodes.Add(effect); |
| 116 | end; |
| 117 | end; |
| 118 | end; |
| 119 | |
| 120 | |
| 121 | end. |