forked from OpenBazaar/openbazaar-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
51 lines (43 loc) · 1.25 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package test
import (
"net/http"
"os"
"path"
"github.com/OpenBazaar/openbazaar-go/repo"
)
// NewAPIConfig returns a new config object for the API tests
func NewAPIConfig() (*repo.APIConfig, error) {
apiConfig, err := repo.GetAPIConfig(path.Join(GetRepoPath(), "config"))
if err != nil {
return nil, err
}
apiConfig.Authenticated = true
apiConfig.Username = "test"
apiConfig.Password = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" // sha256("test")
corsOrigin := "example.com"
apiConfig.CORS = &corsOrigin
return apiConfig, nil
}
// GetRepoPath returns the repo path to use for tests
// It should be considered volitile and may be destroyed at any time
func GetRepoPath() string {
return getEnvString("OPENBAZAAR_TEST_REPO_PATH", "/tmp/openbazaar-test")
}
// GetPassword returns a static mneumonic to use
func GetPassword() string {
return getEnvString("OPENBAZAAR_TEST_PASSWORD", "correct horse battery staple")
}
// GetAuthCookie returns a pointer to a test authentication cookie
func GetAuthCookie() *http.Cookie {
return &http.Cookie{
Name: "OpenBazaar_Auth_Cookie",
Value: "supersecret",
}
}
func getEnvString(key string, defaultVal string) string {
val := os.Getenv(key)
if val == "" {
return defaultVal
}
return val
}