Skip to content

Commit 045a08e

Browse files
committed
structured logging
1 parent cf26b21 commit 045a08e

File tree

139 files changed

+1841
-1096
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+1841
-1096
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ DOCKER_IMAGE_VERSION = 3.0.0
22

33
export IDENTIFO_ADMIN_LOGIN = admin@admin.com
44
export IDENTIFO_ADMIN_PASSWORD = password
5-
export NODE_OPTIONS=--openssl-legacy-provider
5+
# export NODE_OPTIONS=--openssl-legacy-provider
66

77
run_boltdb:
88
mkdir -p ./data

api_test/app_settings_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestAppSettings(t *testing.T) {
2121
SetHeader("Digest", "SHA-256="+signature).
2222
SetHeader("Content-Type", "application/json").
2323
Expect(t).
24-
// AssertFunc(dumpResponse).
24+
// AssertFunc(dumpResponse(t)).
2525
Type("json").
2626
Status(200).
2727
JSONSchema("../test/artifacts/api/app_settings_scheme.json").
@@ -45,15 +45,14 @@ func TestAppSettingsCORS(t *testing.T) {
4545
SetHeader("Digest", "SHA-256="+signature).
4646
SetHeader("Content-Type", "application/json").
4747
Expect(t).
48-
// AssertFunc(dumpResponse).
48+
// AssertFunc(dumpResponse(t)).
4949
AssertFunc(func(rsp *http.Response, r *http.Request) error {
5050
header = rsp.Header
5151
return nil
5252
}).
5353
Status(204).
5454
Done()
5555

56-
fmt.Printf("Header %+v\n", header)
5756
assert.Contains(t, header.Get("Access-Control-Allow-Origin"), "http://localhost:3000")
5857
assert.Contains(t, header.Get("Access-Control-Allow-Methods"), "GET")
5958
}

api_test/invites_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestInvite(t *testing.T) {
3535
SetHeader("Content-Type", "application/json").
3636
BodyString(data).
3737
Expect(t).
38-
// AssertFunc(dumpResponse).
38+
// AssertFunc(dumpResponse(t)).
3939
Type("json").
4040
Status(200).
4141
AssertFunc(validateJSON(func(data map[string]interface{}) error {
@@ -47,7 +47,7 @@ func TestInvite(t *testing.T) {
4747

4848
require.NotEmpty(t, at)
4949
data = fmt.Sprintf(`
50-
{
50+
{
5151
"email": "%s",
5252
"access_role": "%s",
5353
"callback_url": "%s",
@@ -65,7 +65,7 @@ func TestInvite(t *testing.T) {
6565
SetHeader("Content-Type", "application/json").
6666
BodyString(data).
6767
Expect(t).
68-
AssertFunc(dumpResponse).
68+
AssertFunc(dumpResponse(t)).
6969
AssertFunc(validateJSON(func(data map[string]interface{}) error {
7070
link = data["link"].(string)
7171
return nil
@@ -108,7 +108,7 @@ func TestInviteWithCustomLoginAppURL(t *testing.T) {
108108
SetHeader("Content-Type", "application/json").
109109
BodyString(data).
110110
Expect(t).
111-
// AssertFunc(dumpResponse).
111+
// AssertFunc(dumpResponse(t)).
112112
Type("json").
113113
Status(200).
114114
AssertFunc(validateJSON(func(data map[string]interface{}) error {
@@ -120,7 +120,7 @@ func TestInviteWithCustomLoginAppURL(t *testing.T) {
120120

121121
require.NotEmpty(t, at)
122122
data = fmt.Sprintf(`
123-
{
123+
{
124124
"email": "%s",
125125
"access_role": "%s",
126126
"callback_url": "%s",
@@ -138,7 +138,7 @@ func TestInviteWithCustomLoginAppURL(t *testing.T) {
138138
SetHeader("Content-Type", "application/json").
139139
BodyString(data).
140140
Expect(t).
141-
AssertFunc(dumpResponse).
141+
AssertFunc(dumpResponse(t)).
142142
AssertFunc(validateJSON(func(data map[string]interface{}) error {
143143
link = data["link"].(string)
144144
return nil

api_test/login_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestLogin(t *testing.T) {
3434
SetHeader("Content-Type", "application/json").
3535
BodyString(data).
3636
Expect(t).
37-
// AssertFunc(dumpResponse).
37+
// AssertFunc(dumpResponse(t)).
3838
Type("json").
3939
Status(200).
4040
JSONSchema("../test/artifacts/api/jwt_token_with_refresh_scheme.json").
@@ -60,7 +60,7 @@ func TestLoginWithNoRefresh(t *testing.T) {
6060
SetHeader("Content-Type", "application/json").
6161
BodyString(data).
6262
Expect(t).
63-
// AssertFunc(dumpResponse).
63+
// AssertFunc(dumpResponse(t)).
6464
AssertFunc(validateJSON(func(data map[string]interface{}) error {
6565
g.Expect(data).To(MatchKeys(IgnoreExtras|IgnoreMissing, Keys{
6666
"access_token": Not(BeZero()),
@@ -81,7 +81,7 @@ func TestLoginWithWrongAppID(t *testing.T) {
8181
request.Post("/auth/login").
8282
SetHeader("X-Identifo-ClientID", "wrong_app_ID").
8383
Expect(t).
84-
AssertFunc(dumpResponse).
84+
AssertFunc(dumpResponse(t)).
8585
AssertFunc(validateJSON(func(data map[string]interface{}) error {
8686
g.Expect(data["error"]).To(MatchAllKeys(Keys{
8787
"id": Equal(string(l.ErrorStorageAPPFindByIDError)),
@@ -115,7 +115,7 @@ func TestLoginWithWrongSignature(t *testing.T) {
115115
SetHeader("Content-Type", "application/json").
116116
BodyString(data).
117117
Expect(t).
118-
AssertFunc(dumpResponse).
118+
AssertFunc(dumpResponse(t)).
119119
Status(400).
120120
AssertFunc(validateJSON(func(data map[string]interface{}) error {
121121
g.Expect(data["error"]).To(MatchAllKeys(Keys{
@@ -145,7 +145,7 @@ func TestLoginTokenClaims(t *testing.T) {
145145
SetHeader("Content-Type", "application/json").
146146
BodyString(data).
147147
Expect(t).
148-
// AssertFunc(dumpResponse).
148+
// AssertFunc(dumpResponse(t)).
149149
Type("json").
150150
AssertFunc(validateJSON(func(data map[string]interface{}) error {
151151
tokenStr = data["access_token"].(string)

api_test/main_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/caarlos0/env"
1919
"github.com/joho/godotenv"
2020
"github.com/madappgang/identifo/v2/config"
21+
"github.com/madappgang/identifo/v2/logging"
2122
"github.com/madappgang/identifo/v2/model"
2223
"github.com/madappgang/identifo/v2/services/mail/mock"
2324
"gopkg.in/h2non/baloo.v3"
@@ -91,7 +92,7 @@ func runServer() (model.Server, *http.Server) {
9192
settings, _ = model.ConfigStorageSettingsFromString("file://../test/artifacts/api/config-mongo.yaml")
9293
}
9394

94-
configStorage, err := config.InitConfigurationStorage(settings)
95+
configStorage, err := config.InitConfigurationStorage(logging.DefaultLogger, settings)
9596
if err != nil {
9697
log.Fatalf("Unable to load config with error: %v", err)
9798
}
@@ -143,10 +144,12 @@ func stopServer(server *http.Server) {
143144
// Helper functions
144145

145146
// DumpResponse
146-
func dumpResponse(res *http.Response, req *http.Request) error {
147-
data, err := httputil.DumpResponse(res, true)
148-
fmt.Printf("Response: %s \n", string(data))
149-
return err
147+
func dumpResponse(t *testing.T) func(res *http.Response, req *http.Request) error {
148+
return func(res *http.Response, req *http.Request) error {
149+
data, err := httputil.DumpResponse(res, true)
150+
t.Logf("Response: %s \n", string(data))
151+
return err
152+
}
150153
}
151154

152155
// DumpResponse

api_test/management_invite_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestManagementResetToken(t *testing.T) {
3030
Expires: time.Now().Add(time.Hour).Unix(),
3131
Host: u.Host,
3232
}
33-
fmt.Println(sd.String())
33+
t.Log(sd.String())
3434
signature := sig.SignString(sd.String(), []byte(cfg.ManagementKeySecret1))
3535

3636
request.Post("/management/token/reset_password").
@@ -42,7 +42,7 @@ func TestManagementResetToken(t *testing.T) {
4242
SetHeader(sig.KeyIDHeaderKey, cfg.ManagementKeyID1).
4343
BodyString(data).
4444
Expect(t).
45-
AssertFunc(dumpResponse).
45+
AssertFunc(dumpResponse(t)).
4646
Type("json").
4747
Status(200).
4848
AssertFunc(validateJSON(func(data map[string]interface{}) error {
@@ -77,7 +77,7 @@ func TestManagementInactiveKey(t *testing.T) {
7777
Expires: time.Now().Add(time.Hour).Unix(),
7878
Host: u.Host,
7979
}
80-
fmt.Println(sd.String())
80+
t.Log(sd.String())
8181
signature := sig.SignString(sd.String(), []byte(cfg.ManagementKeySecret2))
8282

8383
body := ""
@@ -91,7 +91,7 @@ func TestManagementInactiveKey(t *testing.T) {
9191
SetHeader(sig.KeyIDHeaderKey, cfg.ManagementKeyID2).
9292
BodyString(data).
9393
Expect(t).
94-
AssertFunc(dumpResponse).
94+
AssertFunc(dumpResponse(t)).
9595
Status(400).
9696
AssertFunc(validateBodyText(func(b string) error {
9797
body = b
@@ -115,7 +115,7 @@ func TestManagementInviteNoKeyID(t *testing.T) {
115115
SetHeader("Content-Type", "application/json").
116116
BodyString(data).
117117
Expect(t).
118-
AssertFunc(dumpResponse).
118+
AssertFunc(dumpResponse(t)).
119119
Status(400).
120120
AssertFunc(validateBodyText(func(b string) error {
121121
body = b
@@ -141,7 +141,7 @@ func TestManagementInviteWrongKeyID(t *testing.T) {
141141
SetHeader("X-Nl-Key-Id", "AABBCCDDSS").
142142
BodyString(data).
143143
Expect(t).
144-
AssertFunc(dumpResponse).
144+
AssertFunc(dumpResponse(t)).
145145
Status(400).
146146
AssertFunc(validateBodyText(func(b string) error {
147147
body = b

api_test/misconfig_test/cors_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ func TestCorsAlwaysTrue(t *testing.T) {
1616
message = err["message"].(string)
1717
return nil
1818
})).
19-
AssertFunc(dumpResponse).
19+
AssertFunc(dumpResponse(t)).
2020
Status(500).
2121
Done()
2222
assert.NotEmpty(t, message)
23-
assert.Contains(t, message, "DefaultStorage settings: unsupported database type wrong_type")
23+
assert.Contains(t, message, "DefaultStorage settings: unsupported database type 'wrong_type'")
2424
}

api_test/misconfig_test/main_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/caarlos0/env"
1919
"github.com/joho/godotenv"
2020
"github.com/madappgang/identifo/v2/config"
21+
"github.com/madappgang/identifo/v2/logging"
2122
"github.com/madappgang/identifo/v2/model"
2223
"gopkg.in/h2non/baloo.v3"
2324
"gopkg.in/h2non/baloo.v3/assert"
@@ -69,7 +70,7 @@ func runServer() (model.Server, *httptest.Server) {
6970
os.Remove("./db.db")
7071
settings, _ = model.ConfigStorageSettingsFromString("file://./config.yaml")
7172

72-
configStorage, err := config.InitConfigurationStorage(settings)
73+
configStorage, err := config.InitConfigurationStorage(logging.DefaultLogger, settings)
7374
if err != nil {
7475
log.Fatalf("Unable to load config with error: %v", err)
7576
}
@@ -95,10 +96,12 @@ func stopServer(server *httptest.Server) {
9596
// Helper functions
9697

9798
// DumpResponse
98-
func dumpResponse(res *http.Response, req *http.Request) error {
99-
data, err := httputil.DumpResponse(res, true)
100-
fmt.Printf("Response: %s \n", string(data))
101-
return err
99+
func dumpResponse(t *testing.T) func(res *http.Response, req *http.Request) error {
100+
return func(res *http.Response, req *http.Request) error {
101+
data, err := httputil.DumpResponse(res, true)
102+
t.Logf("Response: %s \n", string(data))
103+
return err
104+
}
102105
}
103106

104107
// DumpResponse

api_test/mongo_app_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"os"
55
"testing"
66

7+
"github.com/madappgang/identifo/v2/logging"
78
"github.com/madappgang/identifo/v2/model"
89
"github.com/madappgang/identifo/v2/storage/mongo"
910
"github.com/stretchr/testify/assert"
@@ -17,10 +18,12 @@ func TestAppCRUD(t *testing.T) {
1718

1819
connStr := os.Getenv("IDENTIFO_STORAGE_MONGO_CONN")
1920

20-
s, err := mongo.NewAppStorage(model.MongoDatabaseSettings{
21-
ConnectionString: connStr,
22-
DatabaseName: "test_users",
23-
})
21+
s, err := mongo.NewAppStorage(
22+
logging.DefaultLogger,
23+
model.MongoDatabaseSettings{
24+
ConnectionString: connStr,
25+
DatabaseName: "test_users",
26+
})
2427
require.NoError(t, err)
2528

2629
expectedApp := model.AppData{

api_test/mongo_user_integration_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"os"
55
"testing"
66

7+
"github.com/madappgang/identifo/v2/logging"
78
"github.com/madappgang/identifo/v2/model"
89
"github.com/madappgang/identifo/v2/storage/mongo"
910
"github.com/stretchr/testify/assert"
@@ -18,10 +19,12 @@ func TestFetchUser(t *testing.T) {
1819

1920
connStr := os.Getenv("IDENTIFO_STORAGE_MONGO_CONN")
2021

21-
s, err := mongo.NewUserStorage(model.MongoDatabaseSettings{
22-
ConnectionString: connStr,
23-
DatabaseName: "test_users",
24-
})
22+
s, err := mongo.NewUserStorage(
23+
logging.DefaultLogger,
24+
model.MongoDatabaseSettings{
25+
ConnectionString: connStr,
26+
DatabaseName: "test_users",
27+
})
2528
require.NoError(t, err)
2629

2730
s.(*mongo.UserStorage).ClearAllUserData()

0 commit comments

Comments
 (0)