|
| 1 | +// Licensed to Elasticsearch B.V. under one or more contributor |
| 2 | +// license agreements. See the NOTICE file distributed with |
| 3 | +// this work for additional information regarding copyright |
| 4 | +// ownership. Elasticsearch B.V. licenses this file to you under |
| 5 | +// the Apache License, Version 2.0 (the "License"); you may |
| 6 | +// not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +//go:build requirefips |
| 19 | + |
| 20 | +package file_integrity |
| 21 | + |
| 22 | +import ( |
| 23 | + "reflect" |
| 24 | + "testing" |
| 25 | + |
| 26 | + "github.com/elastic/elastic-agent-libs/config" |
| 27 | +) |
| 28 | + |
| 29 | +func TestFileParsers(t *testing.T) { |
| 30 | + cfg, err := config.NewConfigFrom(map[string]interface{}{ |
| 31 | + "paths": []string{"/usr/bin"}, |
| 32 | + "file_parsers": []string{"file.elf.sections", `/\.pe\./`}, |
| 33 | + }) |
| 34 | + if err != nil { |
| 35 | + t.Fatal(err) |
| 36 | + } |
| 37 | + |
| 38 | + c := defaultConfig |
| 39 | + if err := cfg.Unpack(&c); err != nil { |
| 40 | + t.Fatal(err) |
| 41 | + } |
| 42 | + |
| 43 | + wantParserNames := map[string]bool{ |
| 44 | + "executable_object": true, |
| 45 | + } |
| 46 | + wantFields := map[string]bool{ |
| 47 | + "file.elf.sections": true, |
| 48 | + "file.pe.sections": true, |
| 49 | + "file.pe.sections.name": true, |
| 50 | + "file.pe.sections.physical_size": true, |
| 51 | + "file.pe.sections.virtual_size": true, |
| 52 | + "file.pe.sections.entropy": true, |
| 53 | + "file.pe.sections.var_entropy": true, |
| 54 | + "file.pe.go_stripped": true, |
| 55 | + } |
| 56 | + |
| 57 | + gotParserNames, gotFields := parserNamesAndFields(c) |
| 58 | + if !reflect.DeepEqual(gotParserNames, wantParserNames) { |
| 59 | + t.Errorf("unexpected parser name set: got:%v want:%v", gotParserNames, wantParserNames) |
| 60 | + } |
| 61 | + if !reflect.DeepEqual(gotFields, wantFields) { |
| 62 | + t.Errorf("unexpected fields set: got:%v want:%v", gotFields, wantFields) |
| 63 | + } |
| 64 | +} |
0 commit comments