mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-08-13 22:15:20 +00:00
Now there is a `install` section in the config that has the fields that previously where in `c3os` but were actually only used during install phase. Also the k3s and c3os config were moved to the provider instead that in the global config.
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package provider_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
providerConfig "github.com/c3os-io/c3os/internal/provider/config"
|
|
|
|
. "github.com/c3os-io/c3os/internal/provider"
|
|
"github.com/c3os-io/c3os/pkg/bus"
|
|
"github.com/mudler/go-pluggable"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
var _ = Describe("Challenge provider", func() {
|
|
Context("network token", func() {
|
|
e := &pluggable.Event{}
|
|
|
|
BeforeEach(func() {
|
|
e = &pluggable.Event{}
|
|
})
|
|
|
|
It("returns it if provided", func() {
|
|
f, err := ioutil.TempFile(os.TempDir(), "tests")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
defer os.RemoveAll(f.Name())
|
|
|
|
cfg := &providerConfig.Config{
|
|
C3OS: &providerConfig.C3OS{
|
|
NetworkToken: "foo",
|
|
},
|
|
}
|
|
d, err := yaml.Marshal(cfg)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
c := &bus.EventPayload{Config: string(d)}
|
|
dat, err := json.Marshal(c)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
e.Data = string(dat)
|
|
resp := Challenge(e)
|
|
|
|
Expect(string(resp.Data)).Should(ContainSubstring("foo"))
|
|
})
|
|
|
|
It("generates it if not provided", func() {
|
|
f, err := ioutil.TempFile(os.TempDir(), "tests")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
defer os.RemoveAll(f.Name())
|
|
|
|
cfg := &providerConfig.Config{
|
|
C3OS: &providerConfig.C3OS{
|
|
NetworkToken: "",
|
|
},
|
|
}
|
|
d, err := yaml.Marshal(cfg)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
c := &bus.EventPayload{Config: string(d)}
|
|
dat, err := json.Marshal(c)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
e.Data = string(dat)
|
|
resp := Challenge(e)
|
|
|
|
Expect(len(string(resp.Data))).Should(BeNumerically(">", 12))
|
|
})
|
|
})
|
|
})
|