Skip to content

Commit 831b41c

Browse files
committed
Refactor test functions for known ZKI and production ping
- Skip test if environment variables are not set - Use environment variables to specify expected ZKI for testing - Update error messages and comments for clarity
1 parent 92f7f1a commit 831b41c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

fiskalhr_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,15 @@ func TestGenerateZKI(t *testing.T) {
140140
// GitHub repository and CI environment, where the correct test certificate is available.
141141

142142
func TestKnownZKI(t *testing.T) {
143+
if os.Getenv("FISKALHRGO_TEST_KNOWN_ZKI") == "" {
144+
t.Skip("Skipping TestKnownZKI because FISKALHRGO_TEST_KNOWN_ZKI environment variable is not set")
145+
}
143146
t.Logf("Testing Known LDT ZKI generation...")
144147

145-
expectedZKI := "0b173c6127809d4f0fff53e13222c819" // This is the ZKI for the test certificate
148+
expectedZKI := os.Getenv("FISKALHRGO_TEST_KNOWN_ZKI") // This is the ZKI for the test certificate
146149

147-
// Check if the external contributor has set their own known ZKI via environment variable
148-
if envZKI := os.Getenv("FISKALHRGO_TEST_KNOWN_ZKI"); envZKI != "" {
149-
expectedZKI = envZKI
150+
if !ValidateZKI(expectedZKI) {
151+
t.Fatalf("Invalid ZKI provided in FISKALHRGO_TEST_KNOWN_ZKI environment variable")
150152
}
151153

152154
timeString := "17.05.2024 16:00:38"
@@ -172,9 +174,8 @@ func TestKnownZKI(t *testing.T) {
172174
if zki != expectedZKI {
173175
t.Error("Note:")
174176
t.Error("- The ZKI (Protection Code) is dependent on the private key used.")
175-
t.Error("- If you're an external contributor and don't have the correct test certificate, this test is expected to fail.")
176-
t.Error("- You can use the FISKALHRGO_TEST_KNOWN_ZKI environment variable to specify your own expected ZKI for testing.")
177-
t.Error("- This test should pass on the official GitHub and CI setup where the correct certificate is available.")
177+
t.Error("- Use the FISKALHRGO_TEST_KNOWN_ZKI environment variable to specify your expected ZKI for testing.")
178+
t.Error("- This test should pass on the official GitHub and CI setup where the correct certificate and ZKI pair is available.")
178179
t.Fatalf("ERROR - Expected ZKI: %s, got %s", expectedZKI, zki)
179180
} else {
180181
t.Log("ZKI matched the expected value.")
@@ -214,8 +215,8 @@ func TestPing(t *testing.T) {
214215
// This test just the SSL connection and production cert verification pool and ping message to the CIS production server
215216
// The rest should be identical to the demo environment and the rest can only be tested in the demo environment ofc.
216217
func TestProductionPing(t *testing.T) {
217-
if os.Getenv("CIStestprodping") == "" {
218-
t.Skip("Skipping TestProductionPing because CIStestprodping environment variable is not set")
218+
if os.Getenv("CISTESTPRODPING") == "" {
219+
t.Skip("Skipping TestProductionPing because CISTESTPRODPING environment variable is not set")
219220
}
220221
t.Log("Testing Production Ping...")
221222
// The path is still to the demo cert, but is not important since we will test only the SSL connection and Echo message

0 commit comments

Comments
 (0)