-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RHINENG-8793 Use /playbooks endpoint to get a playbook for a host
- Loading branch information
1 parent
aff12e7
commit 94191ac
Showing
4 changed files
with
147 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ package v2 | |
|
||
import ( | ||
"bytes" | ||
"config-manager/internal/config" | ||
"config-manager/internal/db" | ||
"config-manager/internal/util" | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
|
@@ -325,3 +327,130 @@ func TestCreateProfile(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestPlaybooks(t *testing.T) { | ||
config.DefaultConfig.PlaybookFiles = "../../../playbooks/" | ||
|
||
tests := []struct { | ||
description string | ||
seed []byte | ||
input request | ||
want string | ||
}{ | ||
{ | ||
description: "get playbook by profile_id", | ||
seed: []byte(`INSERT INTO profiles (profile_id, account_id, org_id, created_at, insights, remediations, compliance) VALUES ('b5db9cbc-4ecd-464b-b416-3a6cd67af87a', '10064', '78606', '` + UNIXTime + `', FALSE, FALSE, FALSE);`), | ||
input: request{ | ||
method: http.MethodGet, | ||
url: "/playbooks?profile_id=b5db9cbc-4ecd-464b-b416-3a6cd67af87a", | ||
headers: map[string]string{ | ||
"X-Rh-Identity": base64.StdEncoding.EncodeToString([]byte(`{"identity":{"account_number":"10064","auth_type":"basic","employee_account_number":"10064","internal":{"org_id":"78606"},"org_id":"78606","type":"User","user":{"email":"[email protected]","first_name":"Maricela","is_active":true,"is_internal":false,"is_org_admin":true,"last_name":"Purdy","locale":"pa","user_id":"algae","username":"torque"}}}`)), | ||
}, | ||
}, | ||
want: `--- | ||
# Service Enablement playbook | ||
# This playbook will take care of all steps required to disable | ||
# Insights Client | ||
- name: Insights Disable | ||
hosts: localhost | ||
become: yes | ||
vars: | ||
insights_signature_exclude: /hosts,/vars/insights_signature | ||
insights_signature: !!binary | | ||
TFMwdExTMUNSVWRKVGlCUVIxQWdVMGxIVGtGVVZWSkZMUzB0TFMwS1ZtVnljMmx2YmpvZ1IyNTFV | ||
RWNnZGpFS0NtbFJTVlpCZDFWQldVODNjekU0ZG5jMU9FUXJhalZ3VGtGUmFGcGlhRUZCYkdkdGFI | ||
WXpZVTR5WjFJM2EwRXdiRVZMSzNNeVVVeGtiSE00YkhSaVZXZ0tORkZoWlZaSVNWa3pPRTVsTXpG | ||
aFJUTkRURFJZV0ZneVVuSlhUbk5QVG5GbFZFUmpPV2xOVERjM05uZzFjbTE2VWk5bFVrbG5NbXg1 | ||
UVRoQkwwOWpOd3A0ZGtkcE1uaHBSRkZVWWtsVE9XaFRTM04yZEZKVllXbHdWWEIwUkV0TVlVcHZN | ||
VTl2Ulhkd2JqQXhUVGMyZDJOQlZqSmxUR1Y0YkhweU5TOXpOazlMQ25oRU4waFFiMjlpU0RGblVG | ||
QjNVbmszZDFadVdIUXhSbE5DYVVKUlYzcE9XRGRzU0hOR1RUaHVjbE01UlhaMWJ6VjBTMmh6Y1Zo | ||
U2VqQnNXR0prWVZnS1NVeERiVWhMVkdjd2JESm9iRTA1V25sS1JqTllNRUpLWVV0dFRWRjFibVpL | ||
Wkd0NlMxSlpOR2QyUTBaTFZGbHBWMEZxZDNFelRreFNTMmQ0Wlhwd1VBcDVlV2xVVTBoRlRrTlZP | ||
RXB2V0Rsa1FuWm5UbUl5TWpreFZIUmxSbGRSVTFGcVlUazRLeXQ2VGpKV2JqVlFNbmN5TlZFd2Iw | ||
ZzBNRGs1Ym5kclVEazJDakptVHk5aVJpOTFTM0l4V1RBelFsSmhaRFEwWmxneGVFYzNlbXBVYUZw | ||
WmNYUjFUM2hyUkVKVk5USkpTRlpaYWxVMFNsVmpPWFUzYUdOTFRYRlNhSG9LVVdKc1EwSnVNMDV2 | ||
YUVsbWEySjFNSGxqVldwQldIcHVOR3hJVTJaNFFreHFOM3BYUVU4MWEwTnNVbm8xVTJScWFIVnFk | ||
bUl3Tms4MlJIRkZWU3MzWkFwVWVVSTRVVXd4Y1VRclp5dFFSV3d2U0RVclZtTm1NRlJST0dnd05G | ||
bHBiVUpOYWpkWVFuQkxVSFpWTlc1WlJVRmtiMVIxWkUwMlpWSk1aRUl2VG5aakNtZExXV1pJTm1G | ||
eGNFMXRiVTFVUTFwTVRFZENLM05yY1ZwdFFVSlJTazV5VlcxM2NYRnlSakJYVVZGMk9HSkxZMFpp | ||
Tm1kb0swbzBlalJLVW5nM1dqWUtkVU5GV2tsRlFVWnRSbkkwTDNjcmJ6QndaM1ZJYlZCRVZrNUZZ | ||
WGhTVWpWMlNFSm9Xa2xRV25wNlUwNXRhMDAwWTNWblZHbDZUM0JMVUhoTVRYWlJTZ3A0U0ZCUFZq | ||
SjFXRUZXTkQwS1BWQkphRThLTFMwdExTMUZUa1FnVUVkUUlGTkpSMDVCVkZWU1JTMHRMUzB0Q2c9 | ||
PQ== | ||
tasks: | ||
- name: Disable the insights-client | ||
command: insights-client --disable-schedule | ||
# This playbook will perform steps required to remove Insights Compliance service from your system. | ||
- name: Compliance OpenSCAP Remove | ||
hosts: localhost | ||
become: yes | ||
vars: | ||
insights_signature_exclude: /hosts,/vars/insights_signature | ||
insights_signature: !!binary | | ||
TFMwdExTMUNSVWRKVGlCUVIxQWdVMGxIVGtGVVZWSkZMUzB0TFMwS1ZtVnljMmx2YmpvZ1IyNTFV | ||
RWNnZGpFS0NtbFJTVlpCZDFWQldVbENSa2c0ZG5jMU9FUXJhalZ3VGtGUmFuSXlRUzhyU3pOa1kw | ||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EZKSWVVb3ZUMkpWUVc5NlQzcGFORUZzVmswMk0zUTNVbUZzTTJvMlkyMW1VbXhD | ||
VlhSQlJsaDNjVFpDYWpSQ2JYUUtSV1ZpY1N0UFl6aDZZM3BIZEVaNU55dHJSa1F6V0VKbGJubFJW | ||
emxrTWk4eU9XWkdNVzF2VmxsVVRXazRiQzlLYVZKU1ZtSlJUelI0TWtwMmVWUTNTQXBMVTBwUlRE | ||
SnZUMnc1T0QwS1BXcEpaa3dLTFMwdExTMUZUa1FnVUVkUUlGTkpSMDVCVkZWU1JTMHRMUzB0Q2c9 | ||
PQ== | ||
tasks: | ||
- name: Compliance OpenSCAP disabled | ||
debug: | ||
msg: "Compliance OpenSCAP is not enabled. Nothing to do"`, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.description, func(t *testing.T) { | ||
if err := db.Open("pgx", DSN); err != nil { | ||
t.Fatalf("failed to open database: %v", err) | ||
} | ||
defer func() { | ||
if err := db.Close(); err != nil { | ||
t.Fatalf("failed to close database: %v", err) | ||
} | ||
}() | ||
|
||
if err := db.Migrate(true); err != nil { | ||
t.Fatalf("failed to migrate database: %v", err) | ||
} | ||
|
||
if err := db.SeedData(test.seed); err != nil { | ||
t.Fatalf("failed to seed database: %v", err) | ||
} | ||
|
||
req := httptest.NewRequest(test.input.method, test.input.url, nil) | ||
for k, v := range test.input.headers { | ||
req.Header.Add(k, v) | ||
} | ||
rr := httptest.NewRecorder() | ||
|
||
router := chi.NewMux() | ||
router.Use(identity.EnforceIdentity) | ||
router.Get("/playbooks", getPlaybook) | ||
router.ServeHTTP(rr, req) | ||
|
||
got := util.NormalizeWhitespace(rr.Body.String()) | ||
test.want = util.NormalizeWhitespace(test.want) | ||
if !cmp.Equal(got, test.want) { | ||
t.Errorf("%v", cmp.Diff(got, test.want)) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package util | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
// NormalizeWhitespace removes extra whitespace characters from a string, | ||
// replacing them with a single space, and trims leading and trailing whitespace. | ||
func NormalizeWhitespace(s string) string { | ||
s = strings.Join(strings.Fields(s), " ") | ||
s = strings.TrimSpace(s) | ||
return s | ||
} |