satellite/consoleweb: fix flaky TestAuth tests

We had a lot of flaky test failures from TestAuth. The error message (WHICH IS NOT VISIBLE IN JEKNINS, only in tests.json):

```
FAIL: TestAuth_Register_NameSpecialChars/Postgres (1.04s)
panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0

goroutine 3473 [running]:

testing.tRunner.func1.2({0x235fe40, 0xc000fe6a08})
	/usr/local/go/src/testing/testing.go:1209 +0x36c
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1212 +0x3b6
panic({0x235fe40, 0xc000fe6a08})
	/usr/local/go/src/runtime/panic.go:1047 +0x266
storj.io/storj/satellite/console/consoleweb/consoleapi_test.TestAuth_Register_NameSpecialChars.func1(0xc001a281a0, 0x289d650, 0xc001a30000)
	/var/lib/jenkins/workspace/storj-gerrit-verify/satellite/console/consoleweb/consoleapi/auth_test.go:773 +0x785
storj.io/storj/private/testplanet.Run.func1.1({0x289c770, 0xc0001b8008})
	/var/lib/jenkins/workspace/storj-gerrit-verify/private/testplanet/run.go:67 +0x732
storj.io/storj/private/testmonkit.RunWith({0x289c770, 0xc0001b8008}, {0x28d89b0, 0xc001a281a0}, {0x1, {0x0, 0x0}, {0x0, 0x0, 0x0}}, ...)
```

The root cause:

testplanet uses a simulated mail sender which clicks to all the registration links by default (async).

These tests creat links and check the unverified users, but without enough luck the mail sender may already clicks to the link which makes the user verified.

Change-Id: I17cd6bf4ae3e7adc223ec693976bb609370f0c44
This commit is contained in:
Márton Elek 2022-08-04 13:31:47 +02:00 committed by Storj Robot
parent d76acda27e
commit 1be5277c2a
3 changed files with 44 additions and 2 deletions

View File

@ -41,6 +41,7 @@ func TestAuth_Register(t *testing.T) {
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
config.Console.OpenRegistrationEnabled = true
config.Console.RateLimit.Burst = 10
config.Mail.AuthType = "nomail"
},
},
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
@ -96,9 +97,11 @@ func TestAuth_Register(t *testing.T) {
require.NoError(t, err)
}()
require.Equal(t, http.StatusOK, result.StatusCode)
require.Len(t, planet.Satellites, 1)
// this works only because we configured 'nomail' above. Mail send simulator won't click to activation link.
_, users, err := planet.Satellites[0].API.Console.Service.GetUserByEmailWithUnverified(ctx, registerData.Email)
require.NoError(t, err)
require.Len(t, users, 1)
require.Equal(t, []byte(test.Partner), users[0].UserAgent)
}()
}
@ -112,6 +115,7 @@ func TestAuth_Register_CORS(t *testing.T) {
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
config.Console.OpenRegistrationEnabled = true
config.Console.RateLimit.Burst = 10
config.Mail.AuthType = "nomail"
},
},
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
@ -192,8 +196,11 @@ func TestAuth_Register_CORS(t *testing.T) {
"Authorization",
})
require.Len(t, planet.Satellites, 1)
// this works only because we configured 'nomail' above. Mail send simulator won't click to activation link.
_, users, err := planet.Satellites[0].API.Console.Service.GetUserByEmailWithUnverified(ctx, email)
require.NoError(t, err)
require.Len(t, users, 1)
require.Equal(t, fullName, users[0].FullName)
})
}
@ -738,6 +745,11 @@ func TestResendActivationEmail(t *testing.T) {
func TestAuth_Register_NameSpecialChars(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 0,
Reconfigure: testplanet.Reconfigure{
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
config.Mail.AuthType = "nomail"
},
},
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
inputName := "The website has been changed to https://evil.com/login.html - Enter Login Details,"
filteredName := "The website has been changed to https---evil-com-login-html - Enter Login Details,"
@ -768,9 +780,11 @@ func TestAuth_Register_NameSpecialChars(t *testing.T) {
require.NoError(t, err)
}()
require.Equal(t, http.StatusOK, result.StatusCode)
require.Len(t, planet.Satellites, 1)
// this works only because we configured 'nomail' above. Mail send simulator won't click to activation link.
_, users, err := planet.Satellites[0].API.Console.Service.GetUserByEmailWithUnverified(ctx, email)
require.NoError(t, err)
require.Len(t, users, 1)
require.Equal(t, filteredName, users[0].FullName)
require.Equal(t, filteredName, users[0].ShortName)
})

View File

@ -0,0 +1,26 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information
package simulate
import (
"context"
"net/mail"
"storj.io/storj/private/post"
)
// NoMail doesn't send out any mail.
type NoMail struct {
}
// SendEmail implements func from mailservice.Sender.
func (n NoMail) SendEmail(ctx context.Context, msg *post.Message) error {
return nil
}
// FromAddress implements func from mailservice.Sender.
func (n NoMail) FromAddress() post.Address {
addr, _ := mail.ParseAddress("nosuchmail@storj.io")
return *addr
}

View File

@ -233,6 +233,8 @@ func setupMailService(log *zap.Logger, config Config) (*mailservice.Service, err
},
ServerAddress: mailConfig.SMTPServerAddress,
}
case "nomail":
sender = simulate.NoMail{}
default:
sender = simulate.NewDefaultLinkClicker(log.Named("mail:linkclicker"))
}