testRouter

Undocumented in source. Be warned that the author may not have intended to support it.
version(unittest)
testRouter
(
bool requireLogin = true
)

Examples

with mandatory auth it should return 401 on missing cookie or useragent

testRouter.request.get("/sites").expectStatusCode(401).end();

with mandatory auth it should return 200 on valid credentials

auto router = testRouter;

router
  .request.get("/sites")
  .header("User-Agent", "something")
  .header("Cookie", "ember_simple_auth-session=%7B%22authenticated%22%3A%7B%22access_token%22%3A%22" ~ bearerToken.name ~ "%22%7D%7D")
  .expectStatusCode(200)
  .end;

with mandatory auth it should return 401 on invalid credentials

auto router = testRouter;

router
  .request.get("/sites")
  .header("User-Agent", "something")
  .header("Cookie", "ember_simple_auth-session=%7B%22authenticated%22%3A%7B%22access_token%22%3A%22%22%7D%7D")
  .expectStatusCode(401)
  .end;

with mandatory auth it should return 401 on missing access token

auto router = testRouter;

router
  .request.get("/sites")
  .header("User-Agent", "something")
  .header("Cookie", "ember_simple_auth-session=%7B%22authenticated%22%3A%7B%7D%7D")
  .expectStatusCode(401)
  .end;

with mandatory auth it should return 401 on missing authenticated data

auto router = testRouter;

router
  .request.get("/sites")
  .header("User-Agent", "something")
  .header("Cookie", "ember_simple_auth-session=%7B%22authenticated%22%3A%7B%7D%7D")
  .expectStatusCode(401)
  .end;

with mandatory auth it should return 401 on invalid json

auto router = testRouter;

router
  .request.get("/sites")
  .header("User-Agent", "something")
  .header("Cookie", "ember_simple_auth-session=authenticated%22%3A%7B%7D%7D")
  .expectStatusCode(401)
  .end;

with mandatory auth it should set the email on valid credentials

testRouter
  .request.get("/email")
  .header("User-Agent", "something")
  .header("Cookie", "ember_simple_auth-session=%7B%22authenticated%22%3A%7B%22access_token%22%3A%22" ~ bearerToken.name ~ "%22%7D%7D")
  .expectStatusCode(200)
  .end((Response response) => {
    response.bodyString.should.equal("user@gmail.com");
  });

with permisive auth it should return 200 on missing cookie or useragent

testRouter(false).request.get("/sites").expectStatusCode(200).end();

with permisive auth it should return 401 on invalid json

testRouter(false)
  .request.get("/sites")
  .header("User-Agent", "something")
  .header("Cookie", "ember_simple_auth-session=authenticated%22%3A%7B%7D%7D")
  .expectStatusCode(401)
  .end;

with permisive auth it should return 401 on invalid credentials

testRouter(false)
  .request.get("/sites")
  .header("User-Agent", "something")
  .header("Cookie", "ember_simple_auth-session=%7B%22authenticated%22%3A%7B%22access_token%22%3A%22%22%7D%7D")
  .expectStatusCode(401)
  .end;

with permisive auth it should return 200 on missing user agent

testRouter(false)
  .request.get("/sites")
  .header("Cookie", "ember_simple_auth-session=%7B%22authenticated%22%3A%7B%22access_token%22%3A%22" ~ bearerToken.name ~ "%22%7D%7D")
  .expectStatusCode(200)
  .end;

with permisive auth it should return 200 on missing token

testRouter(false)
  .request.get("/sites")
  .header("Cookie", "ember_simple_auth-session%3D%7B%22authenticated%22%3A%7B%7D%7D")
  .expectStatusCode(200)
  .end;

with permisive auth it should return 200 on missing ember_simple_auth-session cookie

testRouter(false)
  .request.get("/sites")
  .header("User-Agent", "something")
  .expectStatusCode(200)
  .end;

with permisive auth it should return 200 on valid credentials

testRouter(false)
  .request.get("/sites")
  .header("User-Agent", "something")
  .header("Cookie", "ember_simple_auth-session=%7B%22authenticated%22%3A%7B%22access_token%22%3A%22" ~ bearerToken.name ~ "%22%7D%7D")
  .expectStatusCode(200)
  .end;

with permisive auth it should return 200 on missing authenticated keys

testRouter(false)
  .request.get("/sites")
  .header("User-Agent", "something")
  .header("Cookie", "ember_simple_auth-session=%7B%22authenticated%22%3A%7B%7D%7D")
  .expectStatusCode(200)
  .end;

with permisive auth it should set the email on valid credentials

testRouter(false)
  .request.get("/email")
  .header("User-Agent", "something")
  .header("Cookie", "ember_simple_auth-session=%7B%22authenticated%22%3A%7B%22access_token%22%3A%22" ~ bearerToken.name ~ "%22%7D%7D")
  .expectStatusCode(200)
  .end((Response response) => {
    response.bodyString.should.equal("user@gmail.com");
  });

Meta