Skip to content
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

stabilize threaded unit tests #293

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions licensing/license_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func startPillarMonitor() {
contents := `
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
# https://securityonion.net/license; you may not use this file except in compliance with
# https://securityonion.net/license; you may not use this file except in compliance with
# the Elastic License 2.0.

# Note: Per the Elastic License 2.0, the second limitation states:
Expand All @@ -325,7 +325,7 @@ func startPillarMonitor() {
# in the software, and you may not remove or obscure any functionality in the
# software that is protected by the license key."

# This file is generated by Security Onion and contains a list of license-enabled features.
# This file is generated by Security Onion and contains a list of license-enabled features.
`
features := ListEnabledFeatures()
if manager.status == LICENSE_STATUS_ACTIVE {
Expand Down
30 changes: 14 additions & 16 deletions licensing/license_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/tj/assert"
)

const EXPIRED_KEY = ` H4sIAIvZnGMAA22QR4+bUBSF9/kVFlvPBExz2ZlqijHVNo6yeMaPYsOjPWMgyn8PMyNFihTpLm75zjnS/UXAOIYRzjpIbAiaohfv1Ef5FLX5rAvxRsC+yhqAsxJ9MfR/GASKDwcftnhmZhFELZy9z6yDP1MO7izw5JlmzWz3IAWirx2sSZHdJj4GD/hOUYtpzr9UHy7KtP3rYsBhusYQ4GcDW2Lz4+cb8WxhM7WLKbe8wa+uLaOgySd1inHVbkiyLQv4SmEDv2eoA/mU90bcAAb/UgCVeIK+VzmI4ES0WYI+oyYm8VBxAEZUFbKlp2ugz6t9n15kiX0uligc+es1jf3A7HldUAoctnhtxZ6f7R3+Rc5tOdqqcM5J/F0UyZJh4raOdcNTa6EEyoq+CXR0PloieilIUFlTgwa748r0chJZj2TdmAq3owZi3iFFk4vzx9mUGV41U1N3yLA/GEnCN+tdLa3uAR1zwn6MEh+EmDxefX9VulSjqi6F08hfcQLfYGNXnWxMFpwkKY3h6bJp8bs2z/zRfvCZEu7z3VDh8HRzoOMPa/51S8ho6LrBw7KZgu3qkq7KVGeHu+1Q9LZXkzJDJwaLnnwKpJAbnfkQstcyAlq0ho++q5YLDw11nES0xj+3NmfgvLhYC7rXKFGO927oPHg7oql6MNvDqxMWYxPuBkg/K+Uum/bxnGT90mwjrvZD4+yJmly1Llo+rsGZdZugo307jKf/FbdR950Vr1BHnRrlZMwsACQml/XKq8J5iV5HxgF7sub6Xueyvk7Gfo2Km1AuVZYsWNOv0FEtB4H1WJW/ayfh1S0ZZiB+f/sDb9bxLiEDAAA= `

func awaitPillarMonitor() {
for pillarMonitorCount == 0 {
time.Sleep(50 * time.Millisecond)
}
}

func teardown() {
awaitPillarMonitor()
os.Remove(pillarFilename)
Expand Down Expand Up @@ -259,12 +265,6 @@ func TestValidateDataUrl(tester *testing.T) {
assert.False(tester, ValidateDataUrl("bar"))
}

func awaitPillarMonitor() {
for pillarMonitorCount == 0 {
time.Sleep(50 * time.Millisecond)
}
}

func TestPillarMonitor(tester *testing.T) {
defer setup()()

Expand All @@ -283,19 +283,18 @@ features:
}

func TestPillarMonitorAllFeatures(tester *testing.T) {
Test("", 0, 0, "", "")
defer setup()()

pillarFilename = "/tmp/soc_test_pillar_monitor.sls"
Test("", 0, 0, "", "")

os.Remove(pillarFilename)
startPillarMonitor()
assert.Equal(tester, manager.status, LICENSE_STATUS_ACTIVE)
awaitPillarMonitor()
assert.Equal(tester, LICENSE_STATUS_ACTIVE, manager.status)
contents, _ := os.ReadFile(pillarFilename)

expected := `
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
# https://securityonion.net/license; you may not use this file except in compliance with
# https://securityonion.net/license; you may not use this file except in compliance with
# the Elastic License 2.0.

# Note: Per the Elastic License 2.0, the second limitation states:
Expand All @@ -304,7 +303,7 @@ func TestPillarMonitorAllFeatures(tester *testing.T) {
# in the software, and you may not remove or obscure any functionality in the
# software that is protected by the license key."

# This file is generated by Security Onion and contains a list of license-enabled features.
# This file is generated by Security Onion and contains a list of license-enabled features.
features:
- fips
- oidc
Expand All @@ -322,7 +321,6 @@ func TestPillarMonitor_Fail(tester *testing.T) {

Init("")

assert.Equal(tester, manager.status, LICENSE_STATUS_UNPROVISIONED)
awaitPillarMonitor()
assert.Equal(tester, manager.status, LICENSE_STATUS_INVALID)
assert.Equal(tester, LICENSE_STATUS_INVALID, manager.status)
}