Clamex v0.2.1 Clamex.Scanner.Mock View Source

Mock scanner implementation.

Provides responses without actually running any external scanner behind the scenes.

Link to this section Summary

Functions

Return mocked response depending on value of path argument

Link to this section Functions

Link to this function scan(path) View Source
scan(path :: Path.t) ::
  :ok |
  {:error, atom} |
  {:error, String.t}

Return mocked response depending on value of path argument.

It matches path against one of the defined patterns to decide which response to return.

Defined patterns

  • ~r{virus}
  • ~r{missing}
  • ~r{no-daemon}
  • ~r{no-scanner}

Because of regex-matching, filenames with any leading path or extension can be matched, e.g. "virus.pdf" or "virus/image.png", depending on the test scenario.

Examples

Pretend that file is infected

iex> Clamex.Scanner.Mock.scan("virus.txt")
{:error, :virus_found}

Pretend that file does not exist

iex> Clamex.Scanner.Mock.scan("path/to/missing.png")
{:error, :cannot_access_file}

Pretend that clamd daemon is not running in background

iex> Clamex.Scanner.Mock.scan("no-daemon.pdf")
{:error, :cannot_connect_to_clamd}

Pretend that scanner’s executable is not available

iex> Clamex.Scanner.Mock.scan("no-scanner.csv")
{:error, :scanner_not_available}

Pretend that file is safe

iex> Clamex.Scanner.Mock.scan("anything/else.doc")
:ok