[GH-ISSUE #42] [Bug]: __mock.module_info hasn't enough data #17

Open
opened 2026-06-06 22:10:39 -04:00 by yindo · 0 comments
Owner

Originally created by @0legovich on GitHub (Jan 10, 2023).
Original GitHub issue: https://github.com/vxcontrol/soldr-modules/issues/42

Originally assigned to: @asdek on GitHub.

Describe the bug

I tried to write a simple test for my module and get unexpected error

/soldr-modules/utils/mock/core.lua:864: /soldr-modules/utils/engine/event.lua:488: attempt to call field 'fields_schema_validator' (a nil value)

After a little research, I realized that __mock.module_config hasn't enough data. I found the row with initializing and containing __mock.module_info https://github.com/vxcontrol/soldr-modules/blob/master/utils/mock/core.lua#L693 and was unhappy surprised there are no fields: fields, actions, events. As I understand __mock.module_info should contains data from file <module_name>/<version>/config/info.json.

I crookedly fixed it in my module, but it will be better if __mock.module_info contains real data from <module_name>/<version>/config/info.json.

Steps to Reproduce

cat << EOF > ./tests/osquery_linux_client_spec.lua
require 'busted.runner'()

describe('osquery_linux agent', function()
    setup(function()
        _G.__mock = {
            vars = {},
            timeout = 2, -- in seconds
            cwd = "tmpcwd",
            module = "osquery_linux",
            version = "1.0.0",
            side = "agent",
            log_level = os.getenv("LOG_LEVEL") or "debug", -- error, warn, info, debug, trace
        }
        require("mock")
        __mock:module_start()
    end)

    teardown(function()
        -- stop module actually wait for module coroutine to finish execution
        __mock:module_stop()
    end)

    before_each(function()
        __mock:clear_expectations()
    end)
end)
EOF
  • Run test:
    ./tests_framework/lua/bin/busted.osx64.cmd tests/osquery_linux_client_spec.lua

Expected behavior:

1 success / 0 failures / 0 errors / 0 pending : 0.288752 seconds

Actual behavior:

0 successes / 0 failures / 1 error / 0 pending : 0.213859 seconds

Error → tests/osquery_linux_client_spec.lua @ 4
osquery_linux agent setup
/Users/roman/other/cok/soldr-modules/utils/mock/core.lua:864: /Users/roman/other/cok/soldr-modules/utils/engine/event.lua:493: attempt to call field 'fields_schema_validator' (a nil value)

Screenshots, screen recording, code snippet

No response

Environment information

➜ uname -a
Darwin MacBook-Pro.local 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64 x86_64

Which agent binary used?

  • darwin-amd64
  • linux-386
  • linux-amd64
  • windows-386
  • windows-amd64
Originally created by @0legovich on GitHub (Jan 10, 2023). Original GitHub issue: https://github.com/vxcontrol/soldr-modules/issues/42 Originally assigned to: @asdek on GitHub. ### Describe the bug I tried to write a simple test for my module and get unexpected error ``` /soldr-modules/utils/mock/core.lua:864: /soldr-modules/utils/engine/event.lua:488: attempt to call field 'fields_schema_validator' (a nil value) ``` After a little research, I realized that __mock.module_config hasn't enough data. I found the row with initializing and containing __mock.module_info https://github.com/vxcontrol/soldr-modules/blob/master/utils/mock/core.lua#L693 and was unhappy surprised there are no fields: `fields`, `actions`, `events`. As I understand __mock.module_info should contains data from file `<module_name>/<version>/config/info.json`. I crookedly fixed it in my module, but it will be better if __mock.module_info contains real data from `<module_name>/<version>/config/info.json`. ### Steps to Reproduce * prepare environment by Wiki: https://github.com/vxcontrol/soldr-modules/wiki/Unit-testing * `cd soldr-modules` * `git fetch origin osquery_linux (if not merged)` * Import test code: ```bash cat << EOF > ./tests/osquery_linux_client_spec.lua require 'busted.runner'() describe('osquery_linux agent', function() setup(function() _G.__mock = { vars = {}, timeout = 2, -- in seconds cwd = "tmpcwd", module = "osquery_linux", version = "1.0.0", side = "agent", log_level = os.getenv("LOG_LEVEL") or "debug", -- error, warn, info, debug, trace } require("mock") __mock:module_start() end) teardown(function() -- stop module actually wait for module coroutine to finish execution __mock:module_stop() end) before_each(function() __mock:clear_expectations() end) end) EOF ``` * Run test: `./tests_framework/lua/bin/busted.osx64.cmd tests/osquery_linux_client_spec.lua` Expected behavior: ``` 1 success / 0 failures / 0 errors / 0 pending : 0.288752 seconds ``` Actual behavior: ``` 0 successes / 0 failures / 1 error / 0 pending : 0.213859 seconds Error → tests/osquery_linux_client_spec.lua @ 4 osquery_linux agent setup /Users/roman/other/cok/soldr-modules/utils/mock/core.lua:864: /Users/roman/other/cok/soldr-modules/utils/engine/event.lua:493: attempt to call field 'fields_schema_validator' (a nil value) ``` ### Screenshots, screen recording, code snippet _No response_ ### Environment information ``` ➜ uname -a Darwin MacBook-Pro.local 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64 x86_64 ``` ### Which agent binary used? - [ ] darwin-amd64 - [ ] linux-386 - [ ] linux-amd64 - [ ] windows-386 - [ ] windows-amd64
yindo added the bugtests labels 2026-06-06 22:10:39 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vxcontrol/soldr-modules#17