Skip to content

Commit

Permalink
Seperate different utmp structure definitions (backport #40541) (#40591)
Browse files Browse the repository at this point in the history
* Seperate different utmp structure definitions (#40541)

* Seperate different utmp structure definitions

The amd64 and arm64 utmp structures differ. The PR separates
the definitions of the those structures, separates the test
files, and separates the test data files.

(cherry picked from commit 00e44ba)

---------

Co-authored-by: Nicholas Berlin <56366649+nicholasberlin@users.noreply.github.com>
  • Loading branch information
mergify[bot] and nicholasberlin authored Aug 22, 2024
1 parent bcec891 commit 4022e36
Show file tree
Hide file tree
Showing 9 changed files with 434 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]

*Auditbeat*

- Fix incorrect definition of struct utmp for arm64 {pull}40541[40541]


*Filebeat*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package login
import (
"encoding/binary"
"io"
"io/ioutil"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -37,7 +36,11 @@ func TestData(t *testing.T) {
config["login.wtmp_file_pattern"] = "./testdata/wtmp"
config["login.btmp_file_pattern"] = ""
f := mbtest.NewReportingMetricSetV2WithRegistry(t, config, ab.Registry)
defer f.(*MetricSet).utmpReader.bucket.DeleteBucket()
defer func() {
if err := f.(*MetricSet).utmpReader.bucket.DeleteBucket(); err != nil {
t.Fatalf("received error: %+v", err)
}
}()

events, errs := mbtest.ReportingFetchV2(f)
if len(errs) > 0 {
Expand Down Expand Up @@ -71,7 +74,11 @@ func TestWtmp(t *testing.T) {
config["login.wtmp_file_pattern"] = wtmpFilepath
config["login.btmp_file_pattern"] = ""
f := mbtest.NewReportingMetricSetV2WithRegistry(t, config, ab.Registry)
defer f.(*MetricSet).utmpReader.bucket.DeleteBucket()
defer func() {
if err := f.(*MetricSet).utmpReader.bucket.DeleteBucket(); err != nil {
t.Fatalf("received error: %+v", err)
}
}()

events, errs := mbtest.ReportingFetchV2(f)
if len(errs) > 0 {
Expand Down Expand Up @@ -181,9 +188,13 @@ func TestBtmp(t *testing.T) {

config := getBaseConfig()
config["login.wtmp_file_pattern"] = ""
config["login.btmp_file_pattern"] = "./testdata/btmp*"
config["login.btmp_file_pattern"] = "./testdata/btmp.amd"
f := mbtest.NewReportingMetricSetV2WithRegistry(t, config, ab.Registry)
defer f.(*MetricSet).utmpReader.bucket.DeleteBucket()
defer func() {
if err := f.(*MetricSet).utmpReader.bucket.DeleteBucket(); err != nil {
t.Fatalf("received error: %+v", err)
}
}()

events, errs := mbtest.ReportingFetchV2(f)
if len(errs) > 0 {
Expand Down Expand Up @@ -278,7 +289,7 @@ func getBaseConfig() map[string]interface{} {
// setupTestDir creates a temporary directory, copies the test files into it,
// and returns the path.
func setupTestDir(t *testing.T) string {
tmp, err := ioutil.TempDir("", "auditbeat-login-test-dir")
tmp, err := os.MkdirTemp("", "auditbeat-login-test-dir")
if err != nil {
t.Fatal("failed to create temp dir")
}
Expand All @@ -289,7 +300,7 @@ func setupTestDir(t *testing.T) string {
}

func copyDir(t *testing.T, src, dst string) {
files, err := ioutil.ReadDir(src)
files, err := os.ReadDir(src)
if err != nil {
t.Fatalf("failed to read %v", src)
}
Expand Down
Loading

0 comments on commit 4022e36

Please sign in to comment.