|
| 1 | +local http = require("socket.http") |
| 2 | +local ltn12 = require("ltn12") |
| 3 | +local test_support = require("test_support") |
| 4 | +require 'busted.runner'() |
| 5 | + |
| 6 | +describe("when session startup returns no session", function() |
| 7 | + test_support.start_server({ |
| 8 | + session_start_fails = true, |
| 9 | + }) |
| 10 | + teardown(test_support.stop_server) |
| 11 | + |
| 12 | + local response_body = {} |
| 13 | + local _, status = http.request({ |
| 14 | + url = "http://127.0.0.1/default/t", |
| 15 | + redirect = false, |
| 16 | + sink = ltn12.sink.table(response_body), |
| 17 | + }) |
| 18 | + |
| 19 | + it("returns the startup error without authenticating the request", function() |
| 20 | + assert.are.equals(401, status) |
| 21 | + assert.truthy(string.find(table.concat(response_body), "session start failed", 1, true)) |
| 22 | + end) |
| 23 | +end) |
| 24 | + |
| 25 | +describe("when revocation_fail_mode is closed and the revocation store read fails", function() |
| 26 | + test_support.start_server({ |
| 27 | + revocation_test = { |
| 28 | + fail_mode = "closed", |
| 29 | + get_fails_after = 1, |
| 30 | + }, |
| 31 | + }) |
| 32 | + teardown(test_support.stop_server) |
| 33 | + |
| 34 | + local _, _, cookie = test_support.login() |
| 35 | + |
| 36 | + local response_body = {} |
| 37 | + local _, status = http.request({ |
| 38 | + url = "http://127.0.0.1/default/t", |
| 39 | + headers = { cookie = cookie }, |
| 40 | + redirect = false, |
| 41 | + sink = ltn12.sink.table(response_body), |
| 42 | + }) |
| 43 | + local body = table.concat(response_body) |
| 44 | + |
| 45 | + it("propagates the session start failure", function() |
| 46 | + assert.are.equals(401, status) |
| 47 | + assert.truthy(string.find(body, "unable to check session revocation", 1, true)) |
| 48 | + end) |
| 49 | + |
| 50 | + it("does not authenticate the request", function() |
| 51 | + assert.is_nil(string.find(body, "hello, world!", 1, true)) |
| 52 | + end) |
| 53 | +end) |
| 54 | + |
| 55 | +describe("when revocation_fail_mode is open and the revocation store read fails", function() |
| 56 | + test_support.start_server({ |
| 57 | + revocation_test = { |
| 58 | + fail_mode = "open", |
| 59 | + get_fails_after = 1, |
| 60 | + }, |
| 61 | + }) |
| 62 | + teardown(test_support.stop_server) |
| 63 | + |
| 64 | + local _, _, cookie = test_support.login() |
| 65 | + |
| 66 | + local response_body = {} |
| 67 | + local _, status = http.request({ |
| 68 | + url = "http://127.0.0.1/default/t", |
| 69 | + headers = { cookie = cookie }, |
| 70 | + redirect = false, |
| 71 | + sink = ltn12.sink.table(response_body), |
| 72 | + }) |
| 73 | + |
| 74 | + it("authenticates the request", function() |
| 75 | + assert.are.equals(200, status) |
| 76 | + assert.truthy(string.find(table.concat(response_body), "hello, world!", 1, true)) |
| 77 | + end) |
| 78 | +end) |
| 79 | + |
| 80 | +describe("when revocation_fail_mode is closed and the revocation store is unreachable during logout", function() |
| 81 | + test_support.start_server({ |
| 82 | + revocation_test = { |
| 83 | + fail_mode = "closed", |
| 84 | + set_fails = true, |
| 85 | + }, |
| 86 | + }) |
| 87 | + teardown(test_support.stop_server) |
| 88 | + |
| 89 | + local _, _, cookie = test_support.login() |
| 90 | + |
| 91 | + local response_body = {} |
| 92 | + local _, status = http.request({ |
| 93 | + url = "http://127.0.0.1/default/logout", |
| 94 | + headers = { cookie = cookie }, |
| 95 | + redirect = false, |
| 96 | + sink = ltn12.sink.table(response_body), |
| 97 | + }) |
| 98 | + local body = table.concat(response_body) |
| 99 | + |
| 100 | + it("propagates destroy failure", function() |
| 101 | + assert.are.equals(401, status) |
| 102 | + assert.truthy(string.find(body, "unable to mark session revoked", 1, true)) |
| 103 | + end) |
| 104 | + |
| 105 | + it("leaves the session valid for replay", function() |
| 106 | + local _, replay_status = http.request({ |
| 107 | + url = "http://127.0.0.1/default/t", |
| 108 | + headers = { cookie = cookie }, |
| 109 | + redirect = false, |
| 110 | + }) |
| 111 | + assert.are.equals(200, replay_status) |
| 112 | + end) |
| 113 | +end) |
| 114 | + |
| 115 | +describe("when revocation_fail_mode is open and the revocation store is unreachable during logout", function() |
| 116 | + test_support.start_server({ |
| 117 | + revocation_test = { |
| 118 | + fail_mode = "open", |
| 119 | + set_fails = true, |
| 120 | + }, |
| 121 | + }) |
| 122 | + teardown(test_support.stop_server) |
| 123 | + |
| 124 | + local _, _, cookie = test_support.login() |
| 125 | + |
| 126 | + local _, status = http.request({ |
| 127 | + url = "http://127.0.0.1/default/logout", |
| 128 | + headers = { cookie = cookie }, |
| 129 | + redirect = false, |
| 130 | + }) |
| 131 | + |
| 132 | + it("logout still completes", function() |
| 133 | + assert.are.equals(200, status) |
| 134 | + end) |
| 135 | +end) |
0 commit comments