Skip to content

Commit

Permalink
Replace default reload url
Browse files Browse the repository at this point in the history
This avoid incorrect reload when using the manager
  • Loading branch information
sathieu committed Feb 10, 2018
1 parent 5a2629e commit c35bb44
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
5 changes: 4 additions & 1 deletion internal/filesystem/fake/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ func NewFilesystem() *Filesystem {
content := []byte(`{
"cfgNum": 1,
"exportedHeaders": {},
"locationRules": {}
"locationRules": {},
"reloadUrls": {
"reload.example.com" : "http://reload.example.com/reload"
}
}`)
fs.WriteFile("/var/lib/lemonldap-ng/conf/lmConf-1.js", content, 0644)
return fs
Expand Down
10 changes: 10 additions & 0 deletions internal/lemonldapng/config/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ func (c *Config) Save() error {
}
conf["cfgAuthor"] = "lemonldap-ng-controller"
conf["cfgNum"] = nextConfigNum

// Replace default reload url
reloadUrls, ok := conf["reloadUrls"].(map[string]interface{})
if ok {
if _, ok = reloadUrls["reload.example.com"]; ok {
delete(reloadUrls, "reload.example.com")
reloadUrls["localhost"] = "http://localhost/reload"
}
}

allExportedHeaders, ok := conf["exportedHeaders"].(map[string]interface{})
if !ok {
return fmt.Errorf("exportedHeaders should be a map, got %T", conf["exportedHeaders"])
Expand Down
29 changes: 28 additions & 1 deletion internal/lemonldapng/config/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,33 @@ import (
fakefs "github.com/lemonldap-ng-controller/lemonldap-ng-controller/internal/filesystem/fake"
)

func TestDefaultConfig(t *testing.T) {
flag.Set("alsologtostderr", "true")
fs := fakefs.NewFilesystem()
config := NewConfig(fs, "/var/lib/lemonldap-ng/conf")

config.dirty = true
errSave2 := config.Save()
if errSave2 != nil {
t.Errorf("%s", errSave2)
}
lmConf2, err2 := fs.ReadFile("/var/lib/lemonldap-ng/conf/lmConf-2.js")
if err2 != nil {
t.Errorf("%s", err2)
}
for _, re := range []*regexp.Regexp{
regexp.MustCompile("\"cfgAuthor\": \"lemonldap-ng-controller\","),
regexp.MustCompile("\"cfgNum\": 2,"),
regexp.MustCompile(`"exportedHeaders": {},`),
regexp.MustCompile(`"locationRules": {}`),
regexp.MustCompile(`"reloadUrls": {\s*"localhost": "http://localhost/reload"\s*}`),
} {
if !re.Match(lmConf2) {
t.Errorf("lmConf-2.js to match %s\n%s", re, lmConf2)
}
}
}

func TestAddDeleteVhosts(t *testing.T) {
flag.Set("alsologtostderr", "true")
fs := fakefs.NewFilesystem()
Expand All @@ -46,7 +73,7 @@ func TestAddDeleteVhosts(t *testing.T) {
regexp.MustCompile("\"cfgAuthor\": \"lemonldap-ng-controller\","),
regexp.MustCompile("\"cfgNum\": 2,"),
regexp.MustCompile(`"exportedHeaders": {\s*"test42.example.org": {\s*"Auth-User": "\$uid"\s*}\s*},`),
regexp.MustCompile(`"locationRules": {\s*"test42.example.org": {\s*"default": "accept"\s*}\s*}\s*}`),
regexp.MustCompile(`"locationRules": {\s*"test42.example.org": {\s*"default": "accept"\s*}\s*},`),
} {
if !re.Match(lmConf2) {
t.Errorf("lmConf-2.js to match %s\n%s", re, lmConf2)
Expand Down

0 comments on commit c35bb44

Please sign in to comment.