blob: e672df49a1514de52b32f407865cf6c1ef1c7fbc [file] [log] [blame]
Jon Wayne Parrott0a471d32016-05-19 10:54:38 -07001<html><body>
2<style>
3
4body, h1, h2, h3, div, span, p, pre, a {
5 margin: 0;
6 padding: 0;
7 border: 0;
8 font-weight: inherit;
9 font-style: inherit;
10 font-size: 100%;
11 font-family: inherit;
12 vertical-align: baseline;
13}
14
15body {
16 font-size: 13px;
17 padding: 1em;
18}
19
20h1 {
21 font-size: 26px;
22 margin-bottom: 1em;
23}
24
25h2 {
26 font-size: 24px;
27 margin-bottom: 1em;
28}
29
30h3 {
31 font-size: 20px;
32 margin-bottom: 1em;
33 margin-top: 1em;
34}
35
36pre, code {
37 line-height: 1.5;
38 font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace;
39}
40
41pre {
42 margin-top: 0.5em;
43}
44
45h1, h2, h3, p {
46 font-family: Arial, sans serif;
47}
48
49h1, h2, h3 {
50 border-bottom: solid #CCC 1px;
51}
52
53.toc_element {
54 margin-top: 0.5em;
55}
56
57.firstline {
58 margin-left: 2 em;
59}
60
61.method {
62 margin-top: 1em;
63 border: solid 1px #CCC;
64 padding: 1em;
65 background: #EEE;
66}
67
68.details {
69 font-weight: bold;
70 font-size: 14px;
71}
72
73</style>
74
75<h1><a href="firebaserules_v1.html">Firebase Rules API</a> . <a href="firebaserules_v1.projects.html">projects</a></h1>
76<h2>Instance Methods</h2>
77<p class="toc_element">
78 <code><a href="firebaserules_v1.projects.releases.html">releases()</a></code>
79</p>
80<p class="firstline">Returns the releases Resource.</p>
81
82<p class="toc_element">
83 <code><a href="firebaserules_v1.projects.rulesets.html">rulesets()</a></code>
84</p>
85<p class="firstline">Returns the rulesets Resource.</p>
86
87<p class="toc_element">
Dan O'Mearadd494642020-05-01 07:42:23 -070088 <code><a href="#test">test(name, body=None, x__xgafv=None)</a></code></p>
Sai Cheemalapatie833b792017-03-24 15:06:46 -070089<p class="firstline">Test `Source` for syntactic and semantic correctness. Issues present, if</p>
Jon Wayne Parrott0a471d32016-05-19 10:54:38 -070090<h3>Method Details</h3>
91<div class="method">
Dan O'Mearadd494642020-05-01 07:42:23 -070092 <code class="details" id="test">test(name, body=None, x__xgafv=None)</code>
Sai Cheemalapatie833b792017-03-24 15:06:46 -070093 <pre>Test `Source` for syntactic and semantic correctness. Issues present, if
94any, will be returned to the caller with a description, severity, and
95source location.
Jon Wayne Parrott0a471d32016-05-19 10:54:38 -070096
Sai Cheemalapatie833b792017-03-24 15:06:46 -070097The test method may be executed with `Source` or a `Ruleset` name.
98Passing `Source` is useful for unit testing new rules. Passing a `Ruleset`
99name is useful for regression testing an existing rule.
Jon Wayne Parrott0a471d32016-05-19 10:54:38 -0700100
101The following is an example of `Source` that permits users to upload images
102to a bucket bearing their user id and matching the correct metadata:
103
104_*Example*_
105
106 // Users are allowed to subscribe and unsubscribe to the blog.
107 service firebase.storage {
108 match /users/{userId}/images/{imageName} {
Sai Cheemalapatie833b792017-03-24 15:06:46 -0700109 allow write: if userId == request.auth.uid
Bu Sun Kim65020912020-05-20 12:08:20 -0700110 &amp;&amp; (imageName.matches(&#x27;*.png$&#x27;)
111 || imageName.matches(&#x27;*.jpg$&#x27;))
112 &amp;&amp; resource.mimeType.matches(&#x27;^image/&#x27;)
Jon Wayne Parrott0a471d32016-05-19 10:54:38 -0700113 }
114 }
115
116Args:
Sai Cheemalapatie833b792017-03-24 15:06:46 -0700117 name: string, Tests may either provide `source` or a `Ruleset` resource name.
Jon Wayne Parrott0a471d32016-05-19 10:54:38 -0700118
Sai Cheemalapatie833b792017-03-24 15:06:46 -0700119For tests against `source`, the resource name must refer to the project:
120Format: `projects/{project_id}`
121
122For tests against a `Ruleset`, this must be the `Ruleset` resource name:
123Format: `projects/{project_id}/rulesets/{ruleset_id}` (required)
Dan O'Mearadd494642020-05-01 07:42:23 -0700124 body: object, The request body.
Jon Wayne Parrott0a471d32016-05-19 10:54:38 -0700125 The object takes the form of:
126
127{ # The request for FirebaseRulesService.TestRuleset.
Bu Sun Kim65020912020-05-20 12:08:20 -0700128 &quot;source&quot;: { # `Source` is one or more `File` messages comprising a logical set of rules. # Optional `Source` to be checked for correctness.
Sai Cheemalapatie833b792017-03-24 15:06:46 -0700129 #
130 # This field must not be set when the resource name refers to a `Ruleset`.
Bu Sun Kim65020912020-05-20 12:08:20 -0700131 &quot;files&quot;: [ # `File` set constituting the `Source` bundle.
Jon Wayne Parrott0a471d32016-05-19 10:54:38 -0700132 { # `File` containing source content.
Bu Sun Kim65020912020-05-20 12:08:20 -0700133 &quot;content&quot;: &quot;A String&quot;, # Textual Content.
134 &quot;fingerprint&quot;: &quot;A String&quot;, # Fingerprint (e.g. github sha) associated with the `File`.
135 &quot;name&quot;: &quot;A String&quot;, # File name.
Jon Wayne Parrott0a471d32016-05-19 10:54:38 -0700136 },
137 ],
138 },
Bu Sun Kim65020912020-05-20 12:08:20 -0700139 &quot;testSuite&quot;: { # `TestSuite` is a collection of `TestCase` instances that validate the logical # Inline `TestSuite` to run.
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400140 # correctness of a `Ruleset`. The `TestSuite` may be referenced in-line within
141 # a `TestRuleset` invocation or as part of a `Release` object as a pre-release
142 # check.
Bu Sun Kim65020912020-05-20 12:08:20 -0700143 &quot;testCases&quot;: [ # Collection of test cases associated with the `TestSuite`.
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400144 { # `TestCase` messages provide the request context and an expectation as to
145 # whether the given context will be allowed or denied. Test cases may specify
146 # the `request`, `resource`, and `function_mocks` to mock a function call to
147 # a service-provided function.
148 #
149 # The `request` object represents context present at request-time.
150 #
151 # The `resource` is the value of the target resource as it appears in
152 # persistent storage before the request is executed.
Bu Sun Kim65020912020-05-20 12:08:20 -0700153 &quot;functionMocks&quot;: [ # Optional function mocks for service-defined functions. If not set, any
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400154 # service defined function is expected to return an error, which may or may
155 # not influence the test outcome.
156 { # Mock function definition.
157 #
158 # Mocks must refer to a function declared by the target service. The type of
159 # the function args and result will be inferred at test time. If either the
160 # arg or result values are not compatible with function type declaration, the
161 # request will be considered invalid.
162 #
163 # More than one `FunctionMock` may be provided for a given function name so
164 # long as the `Arg` matchers are distinct. There may be only one function
165 # for a given overload where all `Arg` values are `Arg.any_value`.
Bu Sun Kim65020912020-05-20 12:08:20 -0700166 &quot;args&quot;: [ # The list of `Arg` values to match. The order in which the arguments are
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400167 # provided is the order in which they must appear in the function
168 # invocation.
169 { # Arg matchers for the mock function.
Bu Sun Kim65020912020-05-20 12:08:20 -0700170 &quot;exactValue&quot;: &quot;&quot;, # Argument exactly matches value provided.
171 &quot;anyValue&quot;: { # A generic empty message that you can re-use to avoid defining duplicated # Argument matches any value provided.
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400172 # empty messages in your APIs. A typical example is to use it as the request
173 # or the response type of an API method. For instance:
174 #
175 # service Foo {
176 # rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
177 # }
178 #
179 # The JSON representation for `Empty` is empty JSON object `{}`.
180 },
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400181 },
182 ],
Bu Sun Kim65020912020-05-20 12:08:20 -0700183 &quot;function&quot;: &quot;A String&quot;, # The name of the function.
184 #
185 # The function name must match one provided by a service declaration.
186 &quot;result&quot;: { # Possible result values from the function mock invocation. # The mock result of the function call.
187 &quot;value&quot;: &quot;&quot;, # The result is an actual value. The type of the value must match that
188 # of the type declared by the service.
189 &quot;undefined&quot;: { # A generic empty message that you can re-use to avoid defining duplicated # The result is undefined, meaning the result could not be computed.
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400190 # empty messages in your APIs. A typical example is to use it as the request
191 # or the response type of an API method. For instance:
192 #
193 # service Foo {
194 # rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
195 # }
196 #
197 # The JSON representation for `Empty` is empty JSON object `{}`.
198 },
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400199 },
200 },
201 ],
Bu Sun Kim65020912020-05-20 12:08:20 -0700202 &quot;pathEncoding&quot;: &quot;A String&quot;, # Specifies whether paths (such as request.path) are encoded and how.
203 &quot;request&quot;: &quot;&quot;, # Request context.
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400204 #
205 # The exact format of the request context is service-dependent. See the
206 # appropriate service documentation for information about the supported
207 # fields and types on the request. Minimally, all services support the
208 # following fields and types:
209 #
210 # Request field | Type
211 # ---------------|-----------------
212 # auth.uid | `string`
Dan O'Mearadd494642020-05-01 07:42:23 -0700213 # auth.token | `map&lt;string, string&gt;`
214 # headers | `map&lt;string, string&gt;`
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400215 # method | `string`
Dan O'Mearadd494642020-05-01 07:42:23 -0700216 # params | `map&lt;string, string&gt;`
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400217 # path | `string`
218 # time | `google.protobuf.Timestamp`
219 #
220 # If the request value is not well-formed for the service, the request will
221 # be rejected as an invalid argument.
Bu Sun Kim65020912020-05-20 12:08:20 -0700222 &quot;expressionReportLevel&quot;: &quot;A String&quot;, # Specifies what should be included in the response.
223 &quot;resource&quot;: &quot;&quot;, # Optional resource value as it appears in persistent storage before the
224 # request is fulfilled.
225 #
226 # The resource type depends on the `request.path` value.
227 &quot;expectation&quot;: &quot;A String&quot;, # Test expectation.
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400228 },
229 ],
230 },
Jon Wayne Parrott0a471d32016-05-19 10:54:38 -0700231 }
232
233 x__xgafv: string, V1 error format.
234 Allowed values
235 1 - v1 error format
236 2 - v2 error format
237
238Returns:
239 An object of the form:
240
241 { # The response for FirebaseRulesService.TestRuleset.
Bu Sun Kim65020912020-05-20 12:08:20 -0700242 &quot;testResults&quot;: [ # The set of test results given the test cases in the `TestSuite`.
Sai Cheemalapatie833b792017-03-24 15:06:46 -0700243 # The results will appear in the same order as the test cases appear in the
244 # `TestSuite`.
245 { # Test result message containing the state of the test as well as a
246 # description and source position for test failures.
Bu Sun Kim65020912020-05-20 12:08:20 -0700247 &quot;functionCalls&quot;: [ # The set of function calls made to service-defined methods.
Sai Cheemalapatie833b792017-03-24 15:06:46 -0700248 #
Bu Sun Kim65020912020-05-20 12:08:20 -0700249 # Function calls are included in the order in which they are encountered
250 # during evaluation, are provided for both mocked and unmocked functions,
251 # and included on the response regardless of the test `state`.
252 { # Represents a service-defined function call that was invoked during test
253 # execution.
254 &quot;args&quot;: [ # The arguments that were provided to the function.
255 &quot;&quot;,
256 ],
257 &quot;function&quot;: &quot;A String&quot;, # Name of the function invoked.
258 },
259 ],
260 &quot;visitedExpressions&quot;: [ # The set of visited permission expressions for a given test. This returns
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700261 # the positions and evaluation results of all visited permission
262 # expressions which were relevant to the test case, e.g.
263 # ```
264 # match /path {
Dan O'Mearadd494642020-05-01 07:42:23 -0700265 # allow read if: &lt;expr&gt;
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700266 # }
267 # ```
268 # For a detailed report of the intermediate evaluation states, see the
269 # `expression_reports` field
270 { # Store the position and access outcome for an expression visited in rules.
Bu Sun Kim65020912020-05-20 12:08:20 -0700271 &quot;value&quot;: &quot;&quot;, # The evaluated value for the visited expression, e.g. true/false
272 &quot;sourcePosition&quot;: { # Position in the `Source` content including its line, column number, and an # Position in the `Source` or `Ruleset` where an expression was visited.
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700273 # index of the `File` in the `Source` message. Used for debug purposes.
Bu Sun Kim65020912020-05-20 12:08:20 -0700274 &quot;line&quot;: 42, # Line number of the source fragment. 1-based.
275 &quot;column&quot;: 42, # First column on the source line associated with the source fragment.
276 &quot;fileName&quot;: &quot;A String&quot;, # Name of the `File`.
277 &quot;currentOffset&quot;: 42, # Start position relative to the beginning of the file.
278 &quot;endOffset&quot;: 42, # End position relative to the beginning of the file.
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700279 },
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700280 },
281 ],
Bu Sun Kim65020912020-05-20 12:08:20 -0700282 &quot;state&quot;: &quot;A String&quot;, # State of the test.
283 &quot;expressionReports&quot;: [ # The mapping from expression in the ruleset AST to the values they were
284 # evaluated to. Partially-nested to mirror AST structure. Note that this
285 # field is actually tracking expressions and not permission statements in
286 # contrast to the &quot;visited_expressions&quot; field above. Literal expressions
287 # are omitted.
288 { # Describes where in a file an expression is found and what it was
289 # evaluated to over the course of its use.
290 &quot;sourcePosition&quot;: { # Position in the `Source` content including its line, column number, and an # Position of expression in original rules source.
291 # index of the `File` in the `Source` message. Used for debug purposes.
292 &quot;line&quot;: 42, # Line number of the source fragment. 1-based.
293 &quot;column&quot;: 42, # First column on the source line associated with the source fragment.
294 &quot;fileName&quot;: &quot;A String&quot;, # Name of the `File`.
295 &quot;currentOffset&quot;: 42, # Start position relative to the beginning of the file.
296 &quot;endOffset&quot;: 42, # End position relative to the beginning of the file.
297 },
298 &quot;children&quot;: [ # Subexpressions
299 # Object with schema name: ExpressionReport
300 ],
301 &quot;values&quot;: [ # Values that this expression evaluated to when encountered.
302 { # Tuple for how many times an Expression was evaluated to a particular
303 # ExpressionValue.
304 &quot;count&quot;: 42, # The amount of times that expression returned.
305 &quot;value&quot;: &quot;&quot;, # The return value of the expression
306 },
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400307 ],
308 },
309 ],
Bu Sun Kim65020912020-05-20 12:08:20 -0700310 &quot;debugMessages&quot;: [ # Debug messages related to test execution issues encountered during
Dan O'Mearadd494642020-05-01 07:42:23 -0700311 # evaluation.
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700312 #
Dan O'Mearadd494642020-05-01 07:42:23 -0700313 # Debug messages may be related to too many or too few invocations of
314 # function mocks or to runtime errors that occur during evaluation.
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700315 #
Bu Sun Kim65020912020-05-20 12:08:20 -0700316 # For example: ```Unable to read variable [name: &quot;resource&quot;]```
317 &quot;A String&quot;,
Dan O'Mearadd494642020-05-01 07:42:23 -0700318 ],
Bu Sun Kim65020912020-05-20 12:08:20 -0700319 &quot;errorPosition&quot;: { # Position in the `Source` content including its line, column number, and an # Position in the `Source` or `Ruleset` where the principle runtime error
320 # occurs.
321 #
322 # Evaluation of an expression may result in an error. Rules are deny by
323 # default, so a `DENY` expectation when an error is generated is valid.
324 # When there is a `DENY` with an error, the `SourcePosition` is returned.
325 #
326 # E.g. `error_position { line: 19 column: 37 }`
327 # index of the `File` in the `Source` message. Used for debug purposes.
328 &quot;line&quot;: 42, # Line number of the source fragment. 1-based.
329 &quot;column&quot;: 42, # First column on the source line associated with the source fragment.
330 &quot;fileName&quot;: &quot;A String&quot;, # Name of the `File`.
331 &quot;currentOffset&quot;: 42, # Start position relative to the beginning of the file.
332 &quot;endOffset&quot;: 42, # End position relative to the beginning of the file.
333 },
Sai Cheemalapatie833b792017-03-24 15:06:46 -0700334 },
335 ],
Bu Sun Kim65020912020-05-20 12:08:20 -0700336 &quot;issues&quot;: [ # Syntactic and semantic `Source` issues of varying severity. Issues of
Jon Wayne Parrott0a471d32016-05-19 10:54:38 -0700337 # `ERROR` severity will prevent tests from executing.
338 { # Issues include warnings, errors, and deprecation notices.
Bu Sun Kim65020912020-05-20 12:08:20 -0700339 &quot;sourcePosition&quot;: { # Position in the `Source` content including its line, column number, and an # Position of the issue in the `Source`.
Jon Wayne Parrott0a471d32016-05-19 10:54:38 -0700340 # index of the `File` in the `Source` message. Used for debug purposes.
Bu Sun Kim65020912020-05-20 12:08:20 -0700341 &quot;line&quot;: 42, # Line number of the source fragment. 1-based.
342 &quot;column&quot;: 42, # First column on the source line associated with the source fragment.
343 &quot;fileName&quot;: &quot;A String&quot;, # Name of the `File`.
344 &quot;currentOffset&quot;: 42, # Start position relative to the beginning of the file.
345 &quot;endOffset&quot;: 42, # End position relative to the beginning of the file.
Jon Wayne Parrott0a471d32016-05-19 10:54:38 -0700346 },
Bu Sun Kim65020912020-05-20 12:08:20 -0700347 &quot;severity&quot;: &quot;A String&quot;, # The severity of the issue.
348 &quot;description&quot;: &quot;A String&quot;, # Short error description.
Jon Wayne Parrott0a471d32016-05-19 10:54:38 -0700349 },
350 ],
351 }</pre>
352</div>
353
354</body></html>