Skip to content

Rules for checking if a user exists

Lu edited this page May 24, 2023 · 1 revision

This describes every type and variation of rule one can append to use the general internal logic for deciding on the existence of a user.


Status Code

The most often seen method to identify whether a user exists or not, is to just check the response code of that webpage. To use such a rule, you need to follow this syntax:

status_code <operator> <value>
|            |          |
|            |          └─ Any integer, for code 2XX use 2, for 3XX use 3*
|            |
|            └─ one of ==, !=, <, >
|
└─ identifier of that rule

* The status_code get's restlessly divided by 100, that why you need to use 2, 3, 4, etc. instead of the specific response code.

  • Status code equals sth: status_code == 2
  • Status code does not equal sth: status_code != 4
  • Status code is higher than sth: status_code > 2
  • Status code is lower than sth: status_code < 4

Containment

If the request method is GET, you can not only check the status_code as explained above, but you can also check for keywords in the response text. The syntax for such a rule uses this pattern:

contains <any pattern you might wanna use>
or 
contains not <any pattern you might wanna use>

The string contains is the identifier for that rule, the not negates the underlaying == operator.

  • Response contains something: contains some text
  • Response does not contain something: contains not <title>404</title>

JSON

If the endpoint returns JSON, you can use the following rule syntax to define a condition which decides on whether a user exists or not. The syntax follows this pattern:

json <valid jpath expression> <operator> <value>
|     |                        |          |
|     |                        |          └─ str or int
|     |                        |
|     |                        └─ one of == , !=, <, > 
|     |
|     └─ https://pypi.org/project/jsonpath-python/
|
└─ identifier of that rule

  • Value in JSON equals to sth: json $.key1[0].key2 == exists
  • Value in JSON does not equal to sth: json $.key1[0].key2 != exists
  • Value in JSON is lower than sth: json $.key1[0].key2 < 100
  • Value in JSON is higher than sth: json $.key1[0].key2 > 0

Header

You can also check the response headers for a value. The general pattern for that rule looks like this:

header <header name> <operator> <value>
|       |             |          |
|       |             |          └─ str or int
|       |             |
|       |             └─ one of ==, !=, <, >
|       |
|       └─ Name of the header, for ex. Location
|
└─ identifier of that rule
  • Value exists in header: header Location == value
  • Value does not exist in header: header Location != value
  • Value in header is higher than sth: header Custom > 0
  • Value in header is lower than sth: header Custom < 100

What happens internally?

The rule will be parsed by the method parse_rule(rule) which returns a lambda function that returns the decision (True or False). It also returns the name of that rule, so that the check function knows what value to pass to that lambda function. The return value of that function parse_rule(rule) is Tuple[Callable, str] and can look like this:

return (lambda data: parse_jpath(data, expr) < int(val), "json")
# or
return (lambda status_code: status_code // 100 == int(rule_split[2]), "status_code")