diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a400f68 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: python +sudo: false + +env: + - LUA="lua=5.1" + +before_install: + - sudo apt-get update + - sudo apt-get install -y libssl-dev luarocks + - sudo luarocks install busted + - sudo luarocks install kong + +jobs: + include: + - env: BUID="Plugin Build" + script: sudo luarocks make --pack-binary-rock + - env: BUID="TEST" + script: busted spec/ \ No newline at end of file diff --git a/schema.lua b/schema.lua index 100b47b..af1796c 100644 --- a/schema.lua +++ b/schema.lua @@ -1,6 +1,6 @@ return { no_consumer = true, fields = { - cookie_name = { type = "string", default="SESSION" } + cookie_name = { type = "string", default="SESSION", required = false } } } \ No newline at end of file diff --git a/spec/handler_spec.lua b/spec/handler_spec.lua new file mode 100644 index 0000000..969ff79 --- /dev/null +++ b/spec/handler_spec.lua @@ -0,0 +1,75 @@ +-- local mock_req_headers = { ['Set-Cookie'] = "oauthtoken=13ca678d2aa8454599678e792266ea96; path=/" } +-- local mock_body = '{ "data": "payload_data" }' +-- local mock_ngx_headers = { ['Set-Cookie'] = "oauthtoken=13ca678d2aa8454599678e792266ea96; path=/" } +-- local mock_query_args = "query_args" +-- local mock_resp_headers = {["Set-Cookie"] = "oauthtoken=13ca678d2aa8454599678e792266ea96; path=/;", } +-- local mock_router_matches = { group_one = "test_match" } + +-- local ngx = { +-- log = function() end, +-- config = { +-- subsystem = "http", +-- }, +-- header = { + +-- }, +-- arg = {}, +-- ctx = { +-- buffer = "", +-- }, +-- req = { +-- get_headers = {["Set-Cookie"] = "oauthtoken=13ca678d2aa8454599678e792266ea96; Path=/;",}, +-- set_header = {["Set-Cookie"] = "oauthtoken=13ca678d2aa8454599678e792266ea96; Path=/;",}, +-- }, +-- resp = { +-- get_headers = {["Set-Cookie"] = "oauthtoken=13ca678d2aa8454599678e792266ea96; Path=/;",}, +-- }, +-- var = { +-- _cookie = "13ca678d2aa8454599678e792266ea96", +-- } +-- } + +-- ngx.header["Set-Cookie"] = "oauthtoken=13ca678d2aa8454599678e792266ea96; Path=/;" + +-- _G.ngx = ngx + +-- local CookieToHeaders = require('../handler') + +-- local inspect = require('inspect') + +-- -- describe("Test TemplateTransformerHandler constructor", function() +-- -- it("should set object name correctly", function() +-- -- CookieToHeaders:new() +-- -- assert.equal("cookies-to-headers", CookieToHeaders._name) +-- -- end) +-- -- end) + +-- describe("Test TemplateTransformerHandler header_filter", function() +-- it("should not unset content-length header when there is no templates", function() +-- CookieToHeaders:new() +-- local mock_config = { +-- cookie_name = "oauthtoken" +-- } +-- local cookie = require "resty.cookie" + +-- local ck = cookie:new() + +-- -- local ok, err = ck:set({ key = "ckey", +-- -- value = "cvalue" }) + +-- -- print(ok) +-- local oauthToken, err = ck:get('oauthtoken') +-- if not oauthToken then +-- print(err) +-- else +-- print (oauthToken) +-- end + +-- CookieToHeaders:access(mock_config) +-- -- assert.not_nil(ngx.resp) +-- -- print ( inspect (ngx)) +-- print ( inspect (_G.ngx)) +-- -- assert.equal(mock_resp_headers["Set-Cookie"], "123") +-- -- assert.not_nil(ngx.) +-- end) +-- end) \ No newline at end of file diff --git a/spec/schema_spec.lua b/spec/schema_spec.lua new file mode 100644 index 0000000..d1c1d23 --- /dev/null +++ b/spec/schema_spec.lua @@ -0,0 +1,11 @@ +local schema = require('../schema') + +describe("TestSchema", function() + it("should initialize schema correctly", function() + assert.is_true(schema.no_consumer) + assert.equal("string", schema.fields.cookie_name.type) + assert.equal(false, schema.fields.cookie_name.required) + assert.equal("SESSION", schema.fields.cookie_name.default) + end) + +end)