mirror of
https://github.com/j3ssie/osmedeus.git
synced 2026-09-22 09:34:57 +02:00
- Add ssh_exec() and ssh_rsync() functions for remote command execution and file transfer with connection pooling - Add db_import_dns_asset() to import DNS zone records and group by domain with A/AAAA records stored separately - Add db_import_custom_asset() for flexible JSONL asset import with direct field mapping, supporting tags and custom asset types - Extend Asset model with ExternalURL, Remarks (string array), Language, Size, and LOC fields for better metadata tracking - Add backward compatibility layer for legacy JSON formats (string remarks, tags array merging) - Register new functions in function registry with proper documentation and usage examples
143 lines
3.2 KiB
Go
143 lines
3.2 KiB
Go
package functions
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// --- ssh_exec input validation tests ---
|
|
|
|
func TestSSHExec_EmptyHost(t *testing.T) {
|
|
registry := NewRegistry()
|
|
result, err := registry.Execute(
|
|
`ssh_exec("", "whoami")`,
|
|
map[string]interface{}{},
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "", result)
|
|
}
|
|
|
|
func TestSSHExec_UndefinedHost(t *testing.T) {
|
|
registry := NewRegistry()
|
|
result, err := registry.Execute(
|
|
`ssh_exec(undefined, "whoami")`,
|
|
map[string]interface{}{},
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "", result)
|
|
}
|
|
|
|
func TestSSHExec_EmptyCommand(t *testing.T) {
|
|
registry := NewRegistry()
|
|
result, err := registry.Execute(
|
|
`ssh_exec("10.0.0.1", "")`,
|
|
map[string]interface{}{},
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "", result)
|
|
}
|
|
|
|
func TestSSHExec_UndefinedCommand(t *testing.T) {
|
|
registry := NewRegistry()
|
|
result, err := registry.Execute(
|
|
`ssh_exec("10.0.0.1")`,
|
|
map[string]interface{}{},
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "", result)
|
|
}
|
|
|
|
func TestSSHExec_NoArgs(t *testing.T) {
|
|
registry := NewRegistry()
|
|
result, err := registry.Execute(
|
|
`ssh_exec()`,
|
|
map[string]interface{}{},
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "", result)
|
|
}
|
|
|
|
// --- ssh_rsync input validation tests ---
|
|
|
|
func TestSSHRsync_EmptyHost(t *testing.T) {
|
|
registry := NewRegistry()
|
|
result, err := registry.Execute(
|
|
`ssh_rsync("", "/tmp/src", "/tmp/dest")`,
|
|
map[string]interface{}{},
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, false, result)
|
|
}
|
|
|
|
func TestSSHRsync_UndefinedHost(t *testing.T) {
|
|
registry := NewRegistry()
|
|
result, err := registry.Execute(
|
|
`ssh_rsync(undefined, "/tmp/src", "/tmp/dest")`,
|
|
map[string]interface{}{},
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, false, result)
|
|
}
|
|
|
|
func TestSSHRsync_EmptySrc(t *testing.T) {
|
|
registry := NewRegistry()
|
|
result, err := registry.Execute(
|
|
`ssh_rsync("10.0.0.1", "", "/tmp/dest")`,
|
|
map[string]interface{}{},
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, false, result)
|
|
}
|
|
|
|
func TestSSHRsync_EmptyDest(t *testing.T) {
|
|
registry := NewRegistry()
|
|
result, err := registry.Execute(
|
|
`ssh_rsync("10.0.0.1", "/tmp/src", "")`,
|
|
map[string]interface{}{},
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, false, result)
|
|
}
|
|
|
|
func TestSSHRsync_NoArgs(t *testing.T) {
|
|
registry := NewRegistry()
|
|
result, err := registry.Execute(
|
|
`ssh_rsync()`,
|
|
map[string]interface{}{},
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, false, result)
|
|
}
|
|
|
|
// --- parseSSHConfig tests ---
|
|
|
|
func TestSSHExec_DefaultUserAndPort(t *testing.T) {
|
|
// When only host and command are provided, defaults should be used (user=root, port=22)
|
|
// This will fail to connect but validates that defaults don't cause panics
|
|
registry := NewRegistry()
|
|
result, err := registry.Execute(
|
|
`ssh_exec("192.0.2.1", "echo test")`,
|
|
map[string]interface{}{},
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
// Connection to unreachable host will fail, returns empty string
|
|
assert.Equal(t, "", result)
|
|
}
|
|
|
|
// NOTE: Integration tests for ssh_exec and ssh_rsync against a real SSH server
|
|
// are in the e2e test suite (test-e2e-ssh). Unit tests here only validate
|
|
// input validation since connecting to a real host would be slow/flaky.
|