Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Add wsl linter #980

Merged
merged 3 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ linters:
- unconvert
- unparam
- whitespace
- wsl

issues:
exclude:
Expand Down
3 changes: 3 additions & 0 deletions cmd/authelia-scripts/cmd_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func prepareHostsFile() {

for _, entry := range hostEntries {
domainInHostFile := false

for i, line := range lines {
domainFound := strings.Contains(line, entry.Domain)
ipFound := strings.Contains(line, entry.IP)
Expand Down Expand Up @@ -154,6 +155,7 @@ func readHostsFile() ([]byte, error) {
if err != nil {
return nil, err
}

return bs, nil
}

Expand Down Expand Up @@ -188,6 +190,7 @@ func Bootstrap(cobraCmd *cobra.Command, args []string) {
bootstrapPrintln("Checking if GOPATH is set")

goPathFound := false

for _, v := range os.Environ() {
if strings.HasPrefix(v, "GOPATH=") {
goPathFound = true
Expand Down
2 changes: 2 additions & 0 deletions cmd/authelia-scripts/cmd_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
func buildAutheliaBinary() {
cmd := utils.CommandWithStdout("go", "build", "-o", "../../"+OutputDir+"/authelia")
cmd.Dir = "cmd/authelia"

cmd.Env = append(os.Environ(),
"GOOS=linux", "GOARCH=amd64", "CGO_ENABLED=1")

Expand All @@ -34,6 +35,7 @@ func buildFrontend() {
// Then build the frontend.
cmd = utils.CommandWithStdout("yarn", "build")
cmd.Dir = webDirectory

cmd.Env = append(os.Environ(), "INLINE_RUNTIME_CHUNK=false")

if err := cmd.Run(); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/authelia-scripts/cmd_ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (
// RunCI run the CI scripts.
func RunCI(cmd *cobra.Command, args []string) {
log.Info("=====> Build stage <=====")

if err := utils.CommandWithStdout("authelia-scripts", "--log-level", "debug", "build").Run(); err != nil {
log.Fatal(err)
}

log.Info("=====> Unit testing stage <=====")

if err := utils.CommandWithStdout("authelia-scripts", "--log-level", "debug", "unittest").Run(); err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/authelia-scripts/cmd_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func checkArchIsSupported(arch string) {
return
}
}

log.Fatal("Architecture is not supported. Please select one of " + strings.Join(supportedArch, ", ") + ".")
}

Expand Down Expand Up @@ -90,9 +91,11 @@ func dockerBuildOfficialImage(arch string) error {
cmd.Stdout = nil
cmd.Stderr = nil
commitBytes, err := cmd.Output()

if err != nil {
log.Fatal(err)
}

commitHash := strings.Trim(string(commitBytes), "\n")

return docker.Build(IntermediateDockerImageName, dockerfile, ".", gitTag, commitHash)
Expand Down Expand Up @@ -202,9 +205,9 @@ func publishDockerImage(arch string) {
if ciTag != "" {
if len(tags) == 4 {
log.Infof("Detected tags: '%s' | '%s' | '%s'", tags[1], tags[2], tags[3])

login(docker)
deploy(docker, tags[1]+"-"+arch)

if !ignoredSuffixes.MatchString(ciTag) {
deploy(docker, tags[2]+"-"+arch)
deploy(docker, tags[3]+"-"+arch)
Expand Down Expand Up @@ -233,7 +236,6 @@ func publishDockerManifest() {
if ciTag != "" {
if len(tags) == 4 {
log.Infof("Detected tags: '%s' | '%s' | '%s'", tags[1], tags[2], tags[3])

login(docker)
deployManifest(docker, tags[1], tags[1]+"-amd64", tags[1]+"-arm32v7", tags[1]+"-arm64v8")
publishDockerReadme(docker)
Expand Down
17 changes: 17 additions & 0 deletions cmd/authelia-scripts/cmd_suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func listSuites() []string {
suiteNames := make([]string, 0)
suiteNames = append(suiteNames, suites.GlobalRegistry.Suites()...)
sort.Strings(suiteNames)

return suiteNames
}

Expand All @@ -119,6 +120,7 @@ func checkSuiteAvailable(suite string) error {
return nil
}
}

return ErrNotAvailableSuite
}

Expand All @@ -130,6 +132,7 @@ func runSuiteSetupTeardown(command string, suite string) error {
if err == ErrNotAvailableSuite {
log.Fatal(errors.New("Suite named " + selectedSuite + " does not exist"))
}

log.Fatal(err)
}

Expand All @@ -139,6 +142,7 @@ func runSuiteSetupTeardown(command string, suite string) error {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = os.Environ()

return utils.RunCommandWithTimeout(cmd, s.SetUpTimeout)
}

Expand All @@ -147,6 +151,7 @@ func runOnSetupTimeout(suite string) error {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = os.Environ()

return utils.RunCommandWithTimeout(cmd, 15*time.Second)
}

Expand All @@ -155,26 +160,31 @@ func runOnError(suite string) error {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = os.Environ()

return utils.RunCommandWithTimeout(cmd, 15*time.Second)
}

func setupSuite(suiteName string) error {
log.Infof("Setup environment for suite %s...", suiteName)

signalChannel := make(chan os.Signal)
signal.Notify(signalChannel, os.Interrupt, syscall.SIGTERM)

interrupted := false

go func() {
<-signalChannel

interrupted = true
}()

if errSetup := runSuiteSetupTeardown("setup", suiteName); errSetup != nil || interrupted {
if errSetup == utils.ErrTimeoutReached {
runOnSetupTimeout(suiteName) //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting.
}

teardownSuite(suiteName) //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting.

return errSetup
}

Expand Down Expand Up @@ -230,6 +240,7 @@ func getRunningSuite() (string, error) {
}

b, err := ioutil.ReadFile(runningSuiteFile)

return string(b), err
}

Expand All @@ -247,6 +258,7 @@ func runSuiteTests(suiteName string, withEnv bool) error {
if suite.TestTimeout > 0 {
timeout = fmt.Sprintf("%ds", int64(suite.TestTimeout/time.Second))
}

testCmdLine := fmt.Sprintf("go test -count=1 -v ./internal/suites -timeout %s ", timeout)

if testPattern != "" {
Expand All @@ -262,6 +274,7 @@ func runSuiteTests(suiteName string, withEnv bool) error {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = os.Environ()

if headless {
cmd.Env = append(cmd.Env, "HEADLESS=y")
}
Expand Down Expand Up @@ -293,16 +306,20 @@ func runMultipleSuitesTests(suiteNames []string, withEnv bool) error {
return err
}
}

return nil
}

func runAllSuites() error {
log.Info("Start running all suites")

for _, s := range listSuites() {
if err := runSuiteTests(s, true); err != nil {
return err
}
}

log.Info("All suites passed successfully")

return nil
}
3 changes: 3 additions & 0 deletions cmd/authelia-scripts/cmd_unittest.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import (
// RunUnitTest run the unit tests.
func RunUnitTest(cobraCmd *cobra.Command, args []string) {
log.SetLevel(log.TraceLevel)

if err := utils.Shell("go test $(go list ./... | grep -v suites)").Run(); err != nil {
log.Fatal(err)
}

cmd := utils.Shell("yarn test")
cmd.Dir = webDirectory

cmd.Env = append(os.Environ(), "CI=true")

if err := cmd.Run(); err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/authelia-scripts/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ func levelStringToLevel(level string) log.Level {
} else if level == "warning" {
return log.WarnLevel
}

return log.InfoLevel
}

func main() {
var rootCmd = &cobra.Command{Use: "authelia-scripts"}

cobraCommands := make([]*cobra.Command, 0)

for _, autheliaCommand := range Commands {
Expand All @@ -99,6 +101,7 @@ func main() {
cmdline := autheliaCommand.CommandLine
fn = func(cobraCmd *cobra.Command, args []string) {
cmd := utils.CommandWithStdout(cmdline, args...)

err := cmd.Run()
if err != nil {
panic(err)
Expand Down Expand Up @@ -131,6 +134,7 @@ func main() {

cobraCommands = append(cobraCommands, command)
}

cobraCommands = append(cobraCommands, commands.HashPasswordCmd)

rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "Set the log level for the command")
Expand Down
3 changes: 3 additions & 0 deletions cmd/authelia-suites/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func main() {
rootCmd.AddCommand(setupTimeoutCmd)
rootCmd.AddCommand(errorCmd)
rootCmd.AddCommand(stopCmd)

if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -125,6 +126,7 @@ func setupTimeoutSuite(cmd *cobra.Command, args []string) {
if s.OnSetupTimeout == nil {
return
}

if err := s.OnSetupTimeout(); err != nil {
log.Fatal(err)
}
Expand All @@ -137,6 +139,7 @@ func runErrorCallback(cmd *cobra.Command, args []string) {
if s.OnError == nil {
return
}

if err := s.OnError(); err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/authelia/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func startServer() {
for _, err := range errs {
logging.Logger().Error(err)
}

panic(errors.New("Some errors have been reported"))
}

Expand Down Expand Up @@ -89,6 +90,7 @@ func startServer() {
} else {
log.Fatalf("Unrecognized notifier")
}

if !config.Notifier.DisableStartupCheck {
_, err := notifier.StartupCheck()
if err != nil {
Expand Down
13 changes: 12 additions & 1 deletion internal/authentication/file_user_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func NewFileUserProvider(configuration *schema.FileAuthenticationBackendConfigur
if configuration.Password.Algorithm == sha512 {
cryptAlgo = HashingAlgorithmSHA512
}

settings := getCryptSettings(utils.RandomString(configuration.Password.SaltLength, HashingPossibleSaltCharacters),
cryptAlgo, configuration.Password.Iterations, configuration.Password.Memory*1024, configuration.Password.Parallelism,
configuration.Password.KeyLength)
Expand All @@ -78,6 +79,7 @@ func checkPasswordHashes(database *DatabaseModel) error {
return fmt.Errorf("Unable to parse hash of user %s: %s", u, err)
}
}

return nil
}

Expand All @@ -86,7 +88,9 @@ func readDatabase(path string) (*DatabaseModel, error) {
if err != nil {
return nil, fmt.Errorf("Unable to read database from file %s: %s", path, err)
}

db := DatabaseModel{}

err = yaml.Unmarshal(content, &db)
if err != nil {
return nil, fmt.Errorf("Unable to parse database: %s", err)
Expand All @@ -100,17 +104,20 @@ func readDatabase(path string) (*DatabaseModel, error) {
if !ok {
return nil, fmt.Errorf("The database format is invalid: %s", err)
}

return &db, nil
}

// CheckUserPassword checks if provided password matches for the given user.
func (p *FileUserProvider) CheckUserPassword(username string, password string) (bool, error) {
if details, ok := p.database.Users[username]; ok {
hashedPassword := strings.ReplaceAll(details.HashedPassword, "{CRYPT}", "")

ok, err := CheckPassword(password, hashedPassword)
if err != nil {
return false, err
}

return ok, nil
}

Expand All @@ -130,6 +137,7 @@ func (p *FileUserProvider) GetDetails(username string) (*UserDetails, error) {
Emails: []string{details.Email},
}, nil
}

return nil, fmt.Errorf("User '%s' does not exist in database", username)
}

Expand All @@ -153,11 +161,12 @@ func (p *FileUserProvider) UpdatePassword(username string, newPassword string) e
newPassword, "", algorithm, p.configuration.Password.Iterations,
p.configuration.Password.Memory*1024, p.configuration.Password.Parallelism,
p.configuration.Password.KeyLength, p.configuration.Password.SaltLength)

if err != nil {
return err
}

details.HashedPassword = hash

p.lock.Lock()
p.database.Users[username] = details

Expand All @@ -166,7 +175,9 @@ func (p *FileUserProvider) UpdatePassword(username string, newPassword string) e
p.lock.Unlock()
return err
}

err = ioutil.WriteFile(p.configuration.Path, b, 0644) //nolint:gosec // Fixed in future PR.
p.lock.Unlock()

return err
}
2 changes: 2 additions & 0 deletions internal/authentication/ldap_connection_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (lcf *LDAPConnectionFactoryImpl) DialTLS(network, addr string, config *tls.
if err != nil {
return nil, err
}

return NewLDAPConnectionImpl(conn), nil
}

Expand All @@ -78,5 +79,6 @@ func (lcf *LDAPConnectionFactoryImpl) Dial(network, addr string) (LDAPConnection
if err != nil {
return nil, err
}

return NewLDAPConnectionImpl(conn), nil
}