29 lines
860 B
Go
29 lines
860 B
Go
package config
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"path/filepath"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestDifyRequiresCompleteCredentialsAndAcceptsSecretFiles(t *testing.T) {
|
||
|
|
t.Setenv("DIFY_ENABLED", "true")
|
||
|
|
t.Setenv("DIFY_BRIDGE_SECRET", "")
|
||
|
|
t.Setenv("DIFY_EXTRACTION_API_KEY", "")
|
||
|
|
t.Setenv("DIFY_MEMOIR_API_KEY", "")
|
||
|
|
if _, err := Load("worker"); err == nil {
|
||
|
|
t.Fatal("enabled workflows accepted missing credentials")
|
||
|
|
}
|
||
|
|
for _, name := range []string{"DIFY_BRIDGE_SECRET", "DIFY_EXTRACTION_API_KEY", "DIFY_MEMOIR_API_KEY"} {
|
||
|
|
file := filepath.Join(t.TempDir(), name)
|
||
|
|
if err := os.WriteFile(file, []byte("private-test-value"), 0600); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
t.Setenv(name+"_FILE", file)
|
||
|
|
}
|
||
|
|
cfg, err := Load("worker")
|
||
|
|
if err != nil || !cfg.DifyEnabled || cfg.DifyMemoirAPIKey != "private-test-value" {
|
||
|
|
t.Fatalf("secret-file workflow configuration failed: %v", err)
|
||
|
|
}
|
||
|
|
}
|