mirror of
https://github.com/Lifailon/lazyjournal.git
synced 2026-11-11 01:09:46 +01:00
add pcap test
This commit is contained in:
@@ -92,14 +92,6 @@ jobs:
|
||||
run: cat test-report.md >> $GITHUB_STEP_SUMMARY
|
||||
continue-on-error: true
|
||||
|
||||
- name: Upload markdown report
|
||||
if: ${{ github.event.inputs.testFunctions == 'true' }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: test-report
|
||||
path: test-report.md
|
||||
continue-on-error: true
|
||||
|
||||
- name: Update coverage report
|
||||
if: ${{ github.event.inputs.testFunctions == 'true' }}
|
||||
uses: ncruces/go-coverage-report@v0
|
||||
|
||||
@@ -670,8 +670,8 @@ func (app *App) loadServices(journalName string) {
|
||||
}
|
||||
var bootRecords []BootInfo
|
||||
err = json.Unmarshal(bootOutput, &bootRecords)
|
||||
// Если JSON невалидный
|
||||
if err != nil {
|
||||
// Если JSON невалидный или режим тестирования (Ubuntu 20.04 не поддерживает вывод в формате json)
|
||||
if err != nil || app.testMode {
|
||||
// Парсим вывод построчно
|
||||
lines := strings.Split(string(bootOutput), "\n")
|
||||
for _, line := range lines {
|
||||
@@ -705,7 +705,10 @@ func (app *App) loadServices(journalName string) {
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if err == nil {
|
||||
// Очищаем массив, если он был заполнен в режиме тестирования
|
||||
app.journals = []Journal{}
|
||||
// Добавляем информацию о загрузках в app.journals
|
||||
for _, bootRecord := range bootRecords {
|
||||
// Преобразуем наносекунды в секунды
|
||||
@@ -1199,7 +1202,9 @@ func (app *App) loadFiles(logPath string) {
|
||||
"-name", "*.[0-9]*", "-o",
|
||||
"-name", "*.[0-9].*", "-o",
|
||||
"-name", "*.pcap", "-o",
|
||||
"-name", "*.pcapng",
|
||||
"-name", "*.pcap.*", "-o",
|
||||
"-name", "*.pcapng", "-o",
|
||||
"-name", "*.pcapng.*",
|
||||
)
|
||||
} else {
|
||||
// Загрузка системных журналов для Linux: все файлы, которые содержат log в расширение или названии (архивы включительно), а также расширение с цифрой (архивные) и pcap/pcapng
|
||||
@@ -1211,7 +1216,9 @@ func (app *App) loadFiles(logPath string) {
|
||||
"-name", "*.[0-9]*", "-o",
|
||||
"-name", "*.[0-9].*", "-o",
|
||||
"-name", "*.pcap", "-o",
|
||||
"-name", "*.pcapng",
|
||||
"-name", "*.pcap.*", "-o",
|
||||
"-name", "*.pcapng", "-o",
|
||||
"-name", "*.pcapng.*",
|
||||
)
|
||||
}
|
||||
output, _ = cmd.Output()
|
||||
@@ -1277,6 +1284,10 @@ func (app *App) loadFiles(logPath string) {
|
||||
"-type", "f",
|
||||
"-name", "*.log", "-o",
|
||||
"-name", "*.log.*", "-o",
|
||||
"-name", "*.pcap", "-o",
|
||||
"-name", "*.pcap.*", "-o",
|
||||
"-name", "*.pcapng", "-o",
|
||||
"-name", "*.pcapng.*",
|
||||
)
|
||||
output, _ = cmd.Output()
|
||||
files := strings.Split(strings.TrimSpace(string(output)), "\n")
|
||||
@@ -1327,7 +1338,9 @@ func (app *App) loadFiles(logPath string) {
|
||||
"-name", "*.log", "-o",
|
||||
"-name", "*.asl", "-o",
|
||||
"-name", "*.pcap",
|
||||
"-name", "*.pcap.*",
|
||||
"-name", "*.pcapng",
|
||||
"-name", "*.pcapng.*",
|
||||
")",
|
||||
"-print",
|
||||
)
|
||||
@@ -1359,7 +1372,9 @@ func (app *App) loadFiles(logPath string) {
|
||||
"-type", "f",
|
||||
"-name", "*.log", "-o",
|
||||
"-name", "*.pcap",
|
||||
"-name", "*.pcap.*",
|
||||
"-name", "*.pcapng",
|
||||
"-name", "*.pcapng.*",
|
||||
)
|
||||
outputRootDir, err := cmdRootDir.Output()
|
||||
// Добавляем содержимое директории /root/ в общий массив, если есть доступ
|
||||
|
||||
+72
-17
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
@@ -174,6 +175,36 @@ func TestUnixFiles(t *testing.T) {
|
||||
file.WriteString("| Path | Lines | Read | Color |\n")
|
||||
file.WriteString("|------|-------|------|-------|\n")
|
||||
|
||||
// Создаем временный pcap файл
|
||||
pcapFile := "test.pcap"
|
||||
gzipFile := "test.pcap.gz"
|
||||
file, err := os.Create(pcapFile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Удаляем после теста
|
||||
defer os.Remove(pcapFile)
|
||||
defer file.Close()
|
||||
// Минимальный заголовок, чтобы tcpdump понимал формат
|
||||
pcapHeader := []byte{0xd4, 0xc3, 0xb2, 0xa1, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
||||
file.Write(pcapHeader)
|
||||
// Создаем gzip из pcap файла
|
||||
original, err := os.Open(pcapFile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer original.Close()
|
||||
gzFile, err := os.Create(gzipFile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(gzipFile)
|
||||
defer gzFile.Close()
|
||||
gzWriter := gzip.NewWriter(gzFile)
|
||||
defer gzWriter.Close()
|
||||
// Копируем содержимое pcap в gzip
|
||||
gzWriter.Write(pcapHeader)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
selectPath string
|
||||
@@ -409,21 +440,21 @@ func TestFilterColor(t *testing.T) {
|
||||
"1 line: http://localhost:8443",
|
||||
"2 line: https://github.com/Lifailon/lazyjournal",
|
||||
"3 line: /etc/ssh/sshd_config",
|
||||
"4 line: root",
|
||||
"4 line: root runner",
|
||||
"5 line: warning",
|
||||
"6 line: stderr: disconnected and crashed",
|
||||
"7 line: kernel: deletion removed stopped invalidated aborted blocked deactivated",
|
||||
"8 line: rsyslogd: exited critical failed rejection fataling closed ended dropped killing",
|
||||
"9 line: sudo: cancelation unavailable unsuccessful found denied conflict false none",
|
||||
"10 line: /dev/null null",
|
||||
"11 line: success complete accept connection finish started created enable allowing posted",
|
||||
"10 line: /dev/null",
|
||||
"11 line: null success complete accept connection finish started created enable allowing posted",
|
||||
"12 line: routing forward passed running added opened patching ok available accessible done true",
|
||||
"13 line: stdout input GET SET head request upload listen launch change clear skip missing mount",
|
||||
"14 line: authorization configuration option writing saving boot paused filter normal notice alert",
|
||||
"14 line: authorization configuration options option writing saving booting boot paused filter normal notice alert",
|
||||
"15 line: information update shutdown status debug verbose trace protocol level",
|
||||
"16 line: 0x04",
|
||||
"17 line: 25.02.2025 11:11 11:11:11:11:11:11 11-11-11-11-11-11",
|
||||
"18 line: TCP UDP ICMP IP 192.168.1.1:8443",
|
||||
"16 line: 2025-02-26T21:38:35.956968+03:00 ⎯⎯⎯ 0x04 ⎯⎯⎯",
|
||||
"17 line: 25.02.2025 11:11 11:11:11:11:11:11 11-11-11-11-11-11",
|
||||
"18 line: TCP UDP ICMP IP 192.168.1.1:8443",
|
||||
"19 line: 25.02.2025 01:14:42 [INFO]: not data",
|
||||
"20 line: cron[123]: running",
|
||||
}
|
||||
@@ -613,21 +644,21 @@ func TestMockInterface(t *testing.T) {
|
||||
"1 line: http://localhost:8443",
|
||||
"2 line: https://github.com/Lifailon/lazyjournal",
|
||||
"3 line: /etc/ssh/sshd_config",
|
||||
"4 line: root",
|
||||
"4 line: root runner",
|
||||
"5 line: warning",
|
||||
"6 line: stderr: disconnected and crashed",
|
||||
"7 line: kernel: deletion removed stopped invalidated aborted blocked deactivated",
|
||||
"8 line: rsyslogd: exited critical failed rejection fataling closed ended dropped killing",
|
||||
"9 line: sudo: cancelation unavailable unsuccessful found denied conflict false none",
|
||||
"10 line: /dev/null null",
|
||||
"11 line: success complete accept connection finish started created enable allowing posted",
|
||||
"10 line: /dev/null",
|
||||
"11 line: null success complete accept connection finish started created enable allowing posted",
|
||||
"12 line: routing forward passed running added opened patching ok available accessible done true",
|
||||
"13 line: stdout input GET SET head request upload listen launch change clear skip missing mount",
|
||||
"14 line: authorization configuration option writing saving boot paused filter normal notice alert",
|
||||
"14 line: authorization configuration options option writing saving booting boot paused filter normal notice alert",
|
||||
"15 line: information update shutdown status debug verbose trace protocol level",
|
||||
"16 line: 0x04",
|
||||
"17 line: 25.02.2025 11:11 11:11:11:11:11:11 11-11-11-11-11-11",
|
||||
"18 line: TCP UDP ICMP IP 192.168.1.1:8443",
|
||||
"16 line: 2025-02-26T21:38:35.956968+03:00 ⎯⎯⎯ 0x04 ⎯⎯⎯",
|
||||
"17 line: 25.02.2025 11:11 11:11:11:11:11:11 11-11-11-11-11-11",
|
||||
"18 line: TCP UDP ICMP IP 192.168.1.1:8443",
|
||||
"19 line: 25.02.2025 01:14:42 [INFO]: not data",
|
||||
"20 line: cron[123]: running",
|
||||
}
|
||||
@@ -773,13 +804,37 @@ func TestMockInterface(t *testing.T) {
|
||||
app.nextView(g, nil)
|
||||
time.Sleep(1 * time.Second)
|
||||
if v, err := g.View("logs"); err == nil {
|
||||
app.setCountLogViewDown(g, v)
|
||||
// Right tail count +
|
||||
app.setCountLogViewUp(g, v)
|
||||
time.Sleep(1 * time.Second)
|
||||
app.setCountLogViewUp(g, v)
|
||||
// UP
|
||||
time.Sleep(1 * time.Second)
|
||||
// Left tail count -
|
||||
app.setCountLogViewDown(g, v)
|
||||
time.Sleep(1 * time.Second)
|
||||
app.setCountLogViewDown(g, v)
|
||||
time.Sleep(1 * time.Second)
|
||||
app.setCountLogViewDown(g, v)
|
||||
time.Sleep(1 * time.Second)
|
||||
app.setCountLogViewDown(g, v)
|
||||
time.Sleep(1 * time.Second)
|
||||
app.setCountLogViewDown(g, v)
|
||||
time.Sleep(1 * time.Second)
|
||||
app.setCountLogViewDown(g, v)
|
||||
time.Sleep(1 * time.Second)
|
||||
// Right
|
||||
app.setCountLogViewUp(g, v)
|
||||
time.Sleep(1 * time.Second)
|
||||
app.setCountLogViewUp(g, v)
|
||||
time.Sleep(1 * time.Second)
|
||||
app.setCountLogViewUp(g, v)
|
||||
time.Sleep(1 * time.Second)
|
||||
app.setCountLogViewDown(g, v)
|
||||
time.Sleep(1 * time.Second)
|
||||
// UP output
|
||||
app.scrollUpLogs(1)
|
||||
time.Sleep(1 * time.Second)
|
||||
// DOWN
|
||||
// DOWN output
|
||||
app.scrollDownLogs(1)
|
||||
time.Sleep(1 * time.Second)
|
||||
// Ctrl+A
|
||||
|
||||
Reference in New Issue
Block a user