-
Notifications
You must be signed in to change notification settings - Fork 5k
Enable unit tests with -tags=requirefips #43611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
58c9498
b599a8b
65dcf2a
7afd15f
417f2c9
d47d6ae
d277f10
90c4a27
14d5039
3616e3d
ad3fe0c
6cbfb7d
6b731b9
b8cce79
4ad85c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Licensed to Elasticsearch B.V. under one or more contributor | ||
| // license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright | ||
| // ownership. Elasticsearch B.V. licenses this file to you under | ||
| // the Apache License, Version 2.0 (the "License"); you may | ||
| // not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| //go:build requirefips | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there way to accomplish the variant testing without utilizing build tags? Minimizing the amount of code behind build tags makes maintenance easier. Build tags can hide errors. For example, is there some runtime method of checking if the binary is in FIPS mode (akin to https://pkg.go.dev/crypto/fips140#Enabled) that we can use to skip tests at runtime instead of using build tags?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Our current binaries (built with microsoft/go target fips 140-2) function the same as if the flag has an The next step in our FIPS testing will be to run these unit tests with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't mean to use Then utilize this value to control the expectations set by the tests.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently we don't have anything available in beats. |
||
|
|
||
| package file_integrity | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "testing" | ||
|
|
||
| "github.com/elastic/elastic-agent-libs/config" | ||
| ) | ||
|
|
||
| func TestFileParsers(t *testing.T) { | ||
| cfg, err := config.NewConfigFrom(map[string]interface{}{ | ||
| "paths": []string{"/usr/bin"}, | ||
| "file_parsers": []string{"file.elf.sections", `/\.pe\./`}, | ||
| }) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| c := defaultConfig | ||
| if err := cfg.Unpack(&c); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| wantParserNames := map[string]bool{ | ||
| "executable_object": true, | ||
| } | ||
| wantFields := map[string]bool{ | ||
| "file.elf.sections": true, | ||
| "file.pe.sections": true, | ||
| "file.pe.sections.name": true, | ||
| "file.pe.sections.physical_size": true, | ||
| "file.pe.sections.virtual_size": true, | ||
| "file.pe.sections.entropy": true, | ||
| "file.pe.sections.var_entropy": true, | ||
| "file.pe.go_stripped": true, | ||
| } | ||
|
|
||
| gotParserNames, gotFields := parserNamesAndFields(c) | ||
| if !reflect.DeepEqual(gotParserNames, wantParserNames) { | ||
| t.Errorf("unexpected parser name set: got:%v want:%v", gotParserNames, wantParserNames) | ||
| } | ||
| if !reflect.DeepEqual(gotFields, wantFields) { | ||
| t.Errorf("unexpected fields set: got:%v want:%v", gotFields, wantFields) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.