Skip to content

Commit 8a05a66

Browse files
committed
code review fixes
1 parent 17b7677 commit 8a05a66

File tree

9 files changed

+24
-24
lines changed

9 files changed

+24
-24
lines changed

clientapi/routing/routing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func Setup(
376376
})).Methods(http.MethodPost)
377377
} else {
378378
// If msc3861 is enabled, these endpoints are either redundant or replaced by Matrix Auth Service (MAS)
379-
// Once we migrate to MAS completely, these edndpoints should be removed
379+
// Once we migrate to MAS completely, these endpoints should be removed
380380

381381
v3mux.Handle("/register", httputil.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse {
382382
if r := rateLimits.Limit(req, nil); r != nil {

setup/config/config_clientapi.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ func (c *ClientAPI) Verify(configErrs *ConfigErrors) {
7676
c.RateLimiting.Verify(configErrs)
7777

7878
if c.MSCs.MSC3861Enabled() {
79-
if c.RecaptchaEnabled || !c.RegistrationDisabled {
79+
if !c.RegistrationDisabled || c.RecaptchaEnabled {
8080
configErrs.Add(
81-
"You have enabled the experimental feature MSC3861 which implements the delegated authentication via OIDC." +
82-
"As a result, the feature conflicts with the standard Dendrite's registration and login flows and cannot be used if any of those is enabled." +
81+
"You have enabled the experimental feature MSC3861 which implements the delegated authentication via OIDC. " +
82+
"As a result, the feature conflicts with the standard Dendrite's registration and login flows and cannot be used if any of those is enabled. " +
8383
"You need to disable registration (client_api.registration_disabled) and recapthca (client_api.enable_registration_captcha) options to proceed.",
8484
)
8585
}

setup/config/config_mscs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ type MSCs struct {
1010
// 'msc2836': Threading - https://github.com/matrix-org/matrix-doc/pull/2836
1111
MSCs []string `yaml:"mscs"`
1212

13-
// MSC3861 contains config related to the experimental feature MSC3861. It takes effect only if 'msc3861' is included in 'MSCs' array
13+
// MSC3861 contains config related to the experimental feature MSC3861.
14+
// It takes effect only if 'msc3861' is included in 'MSCs' array.
1415
MSC3861 *MSC3861 `yaml:"msc3861,omitempty"`
1516

1617
Database DatabaseOptions `yaml:"database,omitempty"`

syncapi/syncapi_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ func (s *syncUserAPI) PerformLastSeenUpdate(ctx context.Context, req *userapi.Pe
121121
}
122122

123123
type userVerifier struct {
124-
m map[string]struct {
124+
accessTokenToDeviceAndResponse map[string]struct {
125125
Device *userapi.Device
126126
Response *util.JSONResponse
127127
}
128128
}
129129

130130
func (u *userVerifier) VerifyUserFromRequest(req *http.Request) (*userapi.Device, *util.JSONResponse) {
131-
if pair, ok := u.m[req.URL.Query().Get("access_token")]; ok {
131+
if pair, ok := u.accessTokenToDeviceAndResponse[req.URL.Query().Get("access_token")]; ok {
132132
return pair.Device, pair.Response
133133
}
134134
return nil, nil
@@ -212,13 +212,13 @@ func testSyncAccessTokens(t *testing.T, dbType test.DBType) {
212212
},
213213
}
214214

215-
uv.m = make(map[string]struct {
215+
uv.accessTokenToDeviceAndResponse = make(map[string]struct {
216216
Device *userapi.Device
217217
Response *util.JSONResponse
218218
}, len(testCases))
219219
for _, tc := range testCases {
220220

221-
uv.m[tc.req.URL.Query().Get("access_token")] = struct {
221+
uv.accessTokenToDeviceAndResponse[tc.req.URL.Query().Get("access_token")] = struct {
222222
Device *userapi.Device
223223
Response *util.JSONResponse
224224
}{Device: tc.device, Response: tc.response}
@@ -285,7 +285,7 @@ func testSyncEventFormatPowerLevels(t *testing.T, dbType test.DBType) {
285285
caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics)
286286
natsInstance := jetstream.NATSInstance{}
287287
uv := userVerifier{
288-
m: map[string]struct {
288+
accessTokenToDeviceAndResponse: map[string]struct {
289289
Device *userapi.Device
290290
Response *util.JSONResponse
291291
}{
@@ -539,7 +539,7 @@ func testSyncAPIUpdatePresenceImmediately(t *testing.T, dbType test.DBType) {
539539
jsctx, _ := natsInstance.Prepare(processCtx, &cfg.Global.JetStream)
540540
defer jetstream.DeleteAllStreams(jsctx, &cfg.Global.JetStream)
541541
uv := userVerifier{
542-
m: map[string]struct {
542+
accessTokenToDeviceAndResponse: map[string]struct {
543543
Device *userapi.Device
544544
Response *util.JSONResponse
545545
}{
@@ -669,7 +669,7 @@ func testHistoryVisibility(t *testing.T, dbType test.DBType) {
669669
rsAPI := roomserver.NewInternalAPI(processCtx, cfg, cm, &natsInstance, caches, caching.DisableMetrics)
670670
rsAPI.SetFederationAPI(nil, nil)
671671
uv := userVerifier{
672-
m: map[string]struct {
672+
accessTokenToDeviceAndResponse: map[string]struct {
673673
Device *userapi.Device
674674
Response *util.JSONResponse
675675
}{
@@ -947,7 +947,7 @@ func TestGetMembership(t *testing.T) {
947947
rsAPI := roomserver.NewInternalAPI(processCtx, cfg, cm, &natsInstance, caches, caching.DisableMetrics)
948948
rsAPI.SetFederationAPI(nil, nil)
949949
uv := userVerifier{
950-
m: map[string]struct {
950+
accessTokenToDeviceAndResponse: map[string]struct {
951951
Device *userapi.Device
952952
Response *util.JSONResponse
953953
}{
@@ -1024,7 +1024,7 @@ func testSendToDevice(t *testing.T, dbType test.DBType) {
10241024
defer close()
10251025
natsInstance := jetstream.NATSInstance{}
10261026
uv := userVerifier{
1027-
m: map[string]struct {
1027+
accessTokenToDeviceAndResponse: map[string]struct {
10281028
Device *userapi.Device
10291029
Response *util.JSONResponse
10301030
}{
@@ -1258,7 +1258,7 @@ func testContext(t *testing.T, dbType test.DBType) {
12581258
rsAPI.SetFederationAPI(nil, nil)
12591259

12601260
uv := userVerifier{
1261-
m: map[string]struct {
1261+
accessTokenToDeviceAndResponse: map[string]struct {
12621262
Device *userapi.Device
12631263
Response *util.JSONResponse
12641264
}{
@@ -1446,7 +1446,7 @@ func TestRemoveEditedEventFromSearchIndex(t *testing.T) {
14461446
rsAPI := roomserver.NewInternalAPI(processCtx, cfg, cm, &natsInstance, caches, caching.DisableMetrics)
14471447
rsAPI.SetFederationAPI(nil, nil)
14481448
uv := userVerifier{
1449-
m: map[string]struct {
1449+
accessTokenToDeviceAndResponse: map[string]struct {
14501450
Device *userapi.Device
14511451
Response *util.JSONResponse
14521452
}{

userapi/api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ type LocalpartExternalID struct {
483483
Localpart string
484484
ExternalID string
485485
AuthProvider string
486-
CreatedTs int64
486+
CreatedTS int64
487487
}
488488

489489
// UserInfo is for returning information about the user an OpenID token was issued for

userapi/storage/postgres/accounts_table.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ func (s *accountsStatements) InsertAccount(
116116
localpart string, serverName spec.ServerName,
117117
hash, appserviceID string, accountType api.AccountType,
118118
) (*api.Account, error) {
119-
// TODO: can we replace "UnixNano() / 1M" with "UnixMilli()"?
120-
createdTimeMS := time.Now().UnixNano() / 1000000
119+
createdTimeMS := spec.AsTimestamp(time.Now())
121120
stmt := sqlutil.TxStmt(txn, s.insertAccountStmt)
122121

123122
var err error

userapi/storage/postgres/localpart_external_ids_table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const selectUserExternalIDSQL = "" +
3838
"SELECT localpart, created_ts FROM userapi_localpart_external_ids WHERE external_id = $1 AND auth_provider = $2"
3939

4040
const deleteUserExternalIDSQL = "" +
41-
"SELECT localpart, external_id, auth_provider, created_ts FROM userapi_localpart_external_ids WHERE external_id = $1 AND auth_provider = $2"
41+
"DELETE FROM userapi_localpart_external_ids WHERE external_id = $1 AND auth_provider = $2"
4242

4343
type localpartExternalIDStatements struct {
4444
db *sql.DB
@@ -69,7 +69,7 @@ func (u *localpartExternalIDStatements) Select(ctx context.Context, txn *sql.Tx,
6969
AuthProvider: authProvider,
7070
}
7171
err := u.selectUserExternalIDStmt.QueryRowContext(ctx, externalID, authProvider).Scan(
72-
&ret.Localpart, &ret.CreatedTs,
72+
&ret.Localpart, &ret.CreatedTS,
7373
)
7474
if err != nil {
7575
if err == sql.ErrNoRows {

userapi/storage/sqlite3/accounts_table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (s *accountsStatements) InsertAccount(
116116
ctx context.Context, txn *sql.Tx, localpart string, serverName spec.ServerName,
117117
hash, appserviceID string, accountType api.AccountType,
118118
) (*api.Account, error) {
119-
createdTimeMS := time.Now().UnixNano() / 1000000
119+
createdTimeMS := spec.AsTimestamp(time.Now())
120120
stmt := s.insertAccountStmt
121121

122122
var err error

userapi/storage/sqlite3/localpart_external_ids_table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const selectLocalpartExternalIDSQL = "" +
3838
"SELECT localpart, created_ts FROM userapi_localpart_external_ids WHERE external_id = $1 AND auth_provider = $2"
3939

4040
const deleteLocalpartExternalIDSQL = "" +
41-
"SELECT localpart, external_id, auth_provider, created_ts FROM userapi_localpart_external_ids WHERE external_id = $1 AND auth_provider = $2"
41+
"DELETE FROM userapi_localpart_external_ids WHERE external_id = $1 AND auth_provider = $2"
4242

4343
type localpartExternalIDStatements struct {
4444
db *sql.DB
@@ -69,7 +69,7 @@ func (u *localpartExternalIDStatements) Select(ctx context.Context, txn *sql.Tx,
6969
AuthProvider: authProvider,
7070
}
7171
err := u.selectUserExternalIDStmt.QueryRowContext(ctx, externalID, authProvider).Scan(
72-
&ret.Localpart, &ret.CreatedTs,
72+
&ret.Localpart, &ret.CreatedTS,
7373
)
7474
if err != nil {
7575
if err == sql.ErrNoRows {

0 commit comments

Comments
 (0)