Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
6.5 KiB

  1. Rem
  2. Rem Tests to test the operation cache
  3. Rem
  4. Sub DeleteAFile(filespec)
  5. Dim fso
  6. Set fso = CreateObject("Scripting.FileSystemObject")
  7. fso.DeleteFile(filespec)
  8. End Sub
  9. Rem
  10. Rem To really verify correctness, set the AZDBG environment variable to 202ff then
  11. Rem set Verbose to 1 and follow the instructions
  12. Dim Verbose
  13. Verbose = 0
  14. DeleteAFile("abc.xml")
  15. Dim pAdminManager
  16. Set pAdminManager=CreateObject("AzRoles.AzAdminManager")
  17. pAdminManager.Initialize 1, "msxml://abc.xml"
  18. pAdminManager.Submit
  19. Dim AppHandle1
  20. Set AppHandle1=pAdminManager.CreateApplication("MyApp", 0)
  21. AppHandle1.Submit
  22. Dim OpHandle1
  23. Set OpHandle1=AppHandle1.CreateOperation("Op1", 0)
  24. OpHandle1.Submit
  25. OpHandle1.OperationId = 61
  26. OpHandle1.Submit
  27. Dim OpHandle2
  28. Set OpHandle2=AppHandle1.CreateOperation("Op2", 0)
  29. OpHandle2.Submit
  30. OpHandle2.OperationId = 62
  31. OpHandle2.Submit
  32. Dim GroupHandleA
  33. Set GroupHandleA=AppHandle1.CreateApplicationGroup("GroupWorld", 0)
  34. GroupHandleA.Type = 2
  35. GroupHandleA.AddMember "s-1-1-0"
  36. GroupHandleA.Submit
  37. Dim TaskHandle1
  38. Set TaskHandle1=AppHandle1.CreateTask("TaskOp1", 0)
  39. TaskHandle1.AddOperation "Op1"
  40. TaskHandle1.BizRuleLanguage = "VBScript"
  41. Dim BizRule
  42. BizRule = "Dim Amount" & vbCr
  43. BizRule = BizRule & "Amount = AccessCheck.GetParameter( " & Chr(34) & "Amount" & Chr(34) & ")" & vbCr
  44. BizRule = BizRule & "if Amount < 500 then AccessCheck.BusinessRuleResult = TRUE"
  45. TaskHandle1.BizRule = BizRule
  46. TaskHandle1.Submit
  47. Dim TaskHandle2
  48. Set TaskHandle2=AppHandle1.CreateTask("TaskOp2", 0)
  49. TaskHandle2.AddOperation "Op2"
  50. TaskHandle2.BizRuleLanguage = "VBScript"
  51. BizRule = "Dim Item" & vbCr
  52. BizRule = BizRule & "Item = AccessCheck.GetParameter( " & Chr(34) & "ItemNo" & Chr(34) & ")" & vbCr
  53. BizRule = BizRule & "if Item < 500 then AccessCheck.BusinessRuleResult = TRUE"
  54. TaskHandle2.BizRule = BizRule
  55. TaskHandle2.Submit
  56. Set ScopeHandle1=AppHandle1.CreateScope("MyScopeQ1", 0)
  57. ScopeHandle1.Submit
  58. Set RoleHandleA=ScopeHandle1.CreateRole("RoleLdapCanOp1", 0)
  59. RoleHandleA.AddAppMember "GroupWorld"
  60. RoleHandleA.AddTask "TaskOp1"
  61. RoleHandleA.AddTask "TaskOp2"
  62. Dim Results
  63. Dim Names(50)
  64. Dim Values(50)
  65. Dim Scopes(5)
  66. Dim Operations(10)
  67. Names(0) = "ALL_HTTP"
  68. Values(0) = "HTTP_CONNECTION:Keep-Alive HTTP_ACCEPT:*/* HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_ACCEPT_LANGUAGE:en-us HTTP_HOST:localhost HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3215; .NET CLR 1.0.3415)"
  69. Names(1) = "ALL_RAW"
  70. Values(1) = "Connection: Keep-Alive Accept: */* Accept-Encoding: gzip, deflate Accept-Language: en-us Host: localhost User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3215; .NET CLR 1.0.3415)"
  71. Names(2) = "Amount"
  72. Values(2) = 50
  73. Names(3) = "HTTP_USER_AGENT"
  74. Values(3) = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3215; .NET CLR 1.0.3415)"
  75. Names(4) = "ItemNo"
  76. Values(4) = 53
  77. Names(5) = "V4"
  78. Values(5) = 52
  79. Names(6) = "V7"
  80. Values(6) = 501
  81. Names(7) = "V8"
  82. Values(7) = 500
  83. Scopes(0) = "MyScopeQ1"
  84. Operations(0) = 61
  85. Dim CCHandle
  86. Set CCHandle=AppHandle1.InitializeClientContextFromToken(0, 0)
  87. WScript.Echo "...................."
  88. Results=CCHandle.AccessCheck("MyObject", Scopes, Operations, Names, Values )
  89. If Results(0) = 5 Then
  90. MsgBox("Broken 1")
  91. End if
  92. If Verbose Then MsgBox("Check to ensure the operation cache was primed")
  93. rem Next one should come from the cache
  94. WScript.Echo "...................."
  95. Results=CCHandle.AccessCheck("MyObject", Scopes, Operations, Names, Values )
  96. If Results(0) = 5 Then
  97. MsgBox("Broken 2")
  98. End if
  99. If Verbose Then MsgBox("Check to ensure the operation cache was used")
  100. rem Avoid the cache if the amount changes
  101. WScript.Echo "...................."
  102. Values(2) = 51
  103. Results=CCHandle.AccessCheck("MyObject", Scopes, Operations, Names, Values )
  104. If Results(0) = 5 Then
  105. MsgBox("Broken 3")
  106. End if
  107. If Verbose Then MsgBox("Check to ensure the operation cache wasn't used")
  108. rem Check to ensure we can add an item to an existing cache
  109. WScript.Echo "...................."
  110. Operations(0) = 62
  111. Results=CCHandle.AccessCheck("MyObject", Scopes, Operations, Names, Values )
  112. If Results(0) = 5 Then
  113. MsgBox("Broken 3a")
  114. End if
  115. If Verbose Then MsgBox("Check if ItemNo was added to existing cache")
  116. rem Ensure that didn't flush the "Amount" Cache for Op1
  117. WScript.Echo "...................."
  118. Operations(0) = 61
  119. Results=CCHandle.AccessCheck("MyObject", Scopes, Operations, Names, Values )
  120. If Results(0) = 5 Then
  121. MsgBox("Broken 3b")
  122. End if
  123. If Verbose Then MsgBox("Check if cache used for Op1")
  124. rem Test with duplicate operations from the cache
  125. WScript.Echo "...................."
  126. Operations(0) = 61
  127. Operations(1) = 62
  128. Operations(2) = 61
  129. Results=CCHandle.AccessCheck("MyObject", Scopes, Operations, Names, Values )
  130. If Results(0) = 5 Or Results(1) = 5 Or Results(2) = 5 Then
  131. MsgBox("Broken 3c")
  132. End if
  133. If Verbose Then MsgBox("Check if cache used for Op1/Op2/Op1")
  134. rem Test with duplicate operations after flushing the cache
  135. TaskHandle2.BizRuleLanguage = "VBScript"
  136. WScript.Echo "...................."
  137. Operations(0) = 61
  138. Operations(1) = 62
  139. Operations(2) = 61
  140. Results=CCHandle.AccessCheck("MyObject", Scopes, Operations, Names, Values )
  141. If Results(0) = 5 Or Results(1) = 5 Or Results(2) = 5 Then
  142. MsgBox("Broken 3c")
  143. End if
  144. If Verbose Then MsgBox("Check if cache primed for Op1/Op2/Op1")
  145. Operations(1) = Empty
  146. Operations(2) = Empty
  147. rem build a different bizrule to test BizRuleStrings
  148. WScript.Echo "...................."
  149. BizRule = "AccessCheck.BusinessRuleString =" & Chr(34) & "Bob" & Chr(34)
  150. TaskHandle1.BizRule = BizRule
  151. TaskHandle1.Submit
  152. rem this bizrule string fails and set a bizrule string
  153. Results=CCHandle.AccessCheck("MyObject", Scopes, Operations, Names, Values )
  154. If Results(0) = 5 Then
  155. If CCHandle.GetBusinessRuleString <> "Bob" Then
  156. MsgBox("Error 4: Should be 'Bob':" & CCHandle.GetBusinessRuleString )
  157. End If
  158. Else
  159. MsgBox("Broken 4")
  160. End if
  161. If Verbose Then MsgBox("Check that the op cache wasn't used for Op1")
  162. rem this one too but it comes from the cache
  163. WScript.Echo "...................."
  164. Results=CCHandle.AccessCheck("MyObject", Scopes, Operations, Names, Values )
  165. If Results(0) = 5 Then
  166. If CCHandle.GetBusinessRuleString <> "Bob" Then
  167. MsgBox("Error 4: Should be 'Bob':" & CCHandle.GetBusinessRuleString )
  168. End If
  169. Else
  170. MsgBox("Broken 5")
  171. End if
  172. If Verbose Then MsgBox("Check that the op cache was used for Op1")