-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Francesco Giudici <[email protected]>
- Loading branch information
Showing
2 changed files
with
150 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Copyright © 2022 - 2024 SUSE LLC | ||
Licensed 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. | ||
*/ | ||
|
||
package plainauth | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
elementalv1 "github.com/rancher/elemental-operator/api/v1beta1" | ||
) | ||
|
||
func TestRegisterPlainAuth(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Register PlainAuth") | ||
} | ||
|
||
var _ = Describe("is not filled", Label("plainauth"), func() { | ||
It("returns true when empty", func() { | ||
value := "" | ||
res := isNotFilled(value) | ||
Expect(res).To(BeTrue()) | ||
}) | ||
It("returns true when 'Unspecified'", func() { | ||
value := "Unspecified" | ||
res := isNotFilled(value) | ||
Expect(res).To(BeTrue()) | ||
}) | ||
It("returns true when 'None'", func() { | ||
value := "None" | ||
res := isNotFilled(value) | ||
Expect(res).To(BeTrue()) | ||
}) | ||
It("returns true when 'Not ...'", func() { | ||
value := "Not Present" | ||
res := isNotFilled(value) | ||
Expect(res).To(BeTrue()) | ||
}) | ||
It("returns false when has a regular value", func() { | ||
value := "Data" | ||
res := isNotFilled(value) | ||
Expect(res).To(BeFalse()) | ||
}) | ||
}) | ||
|
||
var _ = Describe("authentication client init", Label("plainauth"), func() { | ||
It("returns error on unknown registration authentication", func() { | ||
reg := elementalv1.Registration{ | ||
Auth: "unknown", | ||
} | ||
authCli := AuthClient{} | ||
err := authCli.Init(reg) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
}) |
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,81 @@ | ||
/* | ||
Copyright © 2022 - 2024 SUSE LLC | ||
Licensed 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. | ||
*/ | ||
|
||
package register | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
elementalv1 "github.com/rancher/elemental-operator/api/v1beta1" | ||
) | ||
|
||
func TestRegisterUtils(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Register Core") | ||
} | ||
|
||
var _ = Describe("authenticator", Label("registration", "core"), func() { | ||
It("returns TPM authentication on auth=tpm registration", func() { | ||
reg := elementalv1.Registration{ | ||
Auth: "tpm", | ||
} | ||
state := &State{} | ||
|
||
auth, err := getAuthenticator(reg, state) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(auth.GetName()).To(Equal("TPM")) | ||
Expect(state.EmulatedTPM).To(BeFalse()) | ||
}) | ||
|
||
It("fills State with TPM emulation data from registration", func() { | ||
reg := elementalv1.Registration{ | ||
Auth: "tpm", | ||
EmulateTPM: true, | ||
EmulatedTPMSeed: 10, | ||
} | ||
state := &State{} | ||
|
||
auth, err := getAuthenticator(reg, state) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(auth.GetName()).To(Equal("TPM")) | ||
Expect(state.EmulatedTPM).To(BeTrue()) | ||
Expect(state.EmulatedTPMSeed).To(Equal(int64(10))) | ||
}) | ||
|
||
It("returns plain authentication on auth=mac registration", func() { | ||
reg := elementalv1.Registration{ | ||
Auth: "mac", | ||
} | ||
state := &State{} | ||
|
||
auth, err := getAuthenticator(reg, state) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(auth.GetName()).To(Equal("Plain")) | ||
}) | ||
|
||
It("returns plain authentication on auth=sys-uuid registration", func() { | ||
reg := elementalv1.Registration{ | ||
Auth: "sys-uuid", | ||
} | ||
state := &State{} | ||
|
||
auth, err := getAuthenticator(reg, state) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(auth.GetName()).To(Equal("Plain")) | ||
}) | ||
}) |