mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-17 02:48:28 -07:00
Merge: *(global): CI scripts
Fix: #1042 * commit '8a05e61feb2a8b7c73c6f4c8f11c5a076c43170b': *: fix auth tests - don't leave repo dirty *: tests mustn't leave repo dirty *: change initDNSServer method, add getDataDir *: fix linter warnings *(global): fix travis config *(global): fix CI scripts *(global): CI scripts
This commit is contained in:
commit
423d311fcb
3
.gitignore
vendored
3
.gitignore
vendored
@ -12,7 +12,8 @@
|
||||
/querylog.json
|
||||
/querylog.json.1
|
||||
/a_main-packr.go
|
||||
coverage.txt
|
||||
|
||||
# Test output
|
||||
dnsfilter/tests/top-1m.csv
|
||||
dnsfilter/tests/dnsfilter.TestLotsOfRules*.pprof
|
||||
dnsfilter/tests/dnsfilter.TestLotsOfRules*.pprof
|
||||
|
@ -38,6 +38,9 @@ linters:
|
||||
- gochecknoinits
|
||||
- prealloc
|
||||
- maligned
|
||||
- godox
|
||||
- funlen
|
||||
- whitespace
|
||||
- goconst # disabled until it's possible to configure
|
||||
fast: true
|
||||
|
||||
|
10
.travis.yml
10
.travis.yml
@ -3,7 +3,6 @@ sudo: false
|
||||
|
||||
go:
|
||||
- 1.12.x
|
||||
- 1.x
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
@ -11,6 +10,7 @@ os:
|
||||
before_install:
|
||||
- nvm install node
|
||||
- npm install -g npm
|
||||
- curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.19.1
|
||||
|
||||
install:
|
||||
- npm --prefix client install
|
||||
@ -22,13 +22,7 @@ cache:
|
||||
- $HOME/Library/Caches/go-build
|
||||
|
||||
script:
|
||||
- node -v
|
||||
- npm -v
|
||||
# Run tests
|
||||
- go test -race -v -bench=. -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
# Make
|
||||
- make build/static/index.html
|
||||
- make
|
||||
- /bin/bash ci.sh
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
36
ci.sh
Executable file
36
ci.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
set -x
|
||||
|
||||
echo "Starting AdGuard Home CI script"
|
||||
|
||||
# Print the current directory contents
|
||||
ls -la
|
||||
|
||||
# Check versions and current directory
|
||||
node -v
|
||||
npm -v
|
||||
go version
|
||||
golangci-lint --version
|
||||
|
||||
# Run linter
|
||||
golangci-lint run
|
||||
|
||||
# Run tests
|
||||
go test -race -v -bench=. -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
|
||||
# Make
|
||||
make clean
|
||||
make build/static/index.html
|
||||
make
|
||||
|
||||
if [[ -z "$(git status --porcelain)" ]]; then
|
||||
# Working directory clean
|
||||
echo "Git status is clean"
|
||||
else
|
||||
echo "Git status is not clean and contains uncommited changes"
|
||||
echo "Please make sure there are no changes"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "AdGuard Home CI script finished successfully"
|
@ -3,6 +3,7 @@ package home
|
||||
import (
|
||||
"encoding/hex"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -10,13 +11,17 @@ import (
|
||||
)
|
||||
|
||||
func TestAuth(t *testing.T) {
|
||||
fn := "./sessions.db"
|
||||
config.ourWorkingDir = "."
|
||||
fn := filepath.Join(config.getDataDir(), "sessions.db")
|
||||
|
||||
_ = os.RemoveAll(config.getDataDir())
|
||||
defer func() { _ = os.RemoveAll(config.getDataDir()) }()
|
||||
|
||||
users := []User{
|
||||
User{Name: "name", PasswordHash: "$2y$05$..vyzAECIhJPfaQiOK17IukcQnqEgKJHy0iETyYqxn3YXJl8yZuo2"},
|
||||
}
|
||||
|
||||
os.Remove(fn)
|
||||
config.ourWorkingDir = "."
|
||||
os.MkdirAll(config.getDataDir(), 0755)
|
||||
a := InitAuth(fn, users)
|
||||
|
||||
assert.True(t, a.CheckSession("notfound") == -1)
|
||||
|
@ -239,6 +239,11 @@ func (c *configuration) getConfigFilename() string {
|
||||
return configFile
|
||||
}
|
||||
|
||||
// getDataDir returns path to the directory where we store databases and filters
|
||||
func (c *configuration) getDataDir() string {
|
||||
return filepath.Join(c.ourWorkingDir, dataDir)
|
||||
}
|
||||
|
||||
// getLogSettings reads logging settings from the config file.
|
||||
// we do it in a separate method in order to configure logger before the actual configuration is parsed and applied.
|
||||
func getLogSettings() logSettings {
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
@ -236,8 +235,7 @@ func handleInstallConfigure(w http.ResponseWriter, r *http.Request) {
|
||||
config.DNS.BindHost = newSettings.DNS.IP
|
||||
config.DNS.Port = newSettings.DNS.Port
|
||||
|
||||
dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir)
|
||||
initDNSServer(dnsBaseDir)
|
||||
initDNSServer()
|
||||
|
||||
err = startDNSServer()
|
||||
if err != nil {
|
||||
@ -263,7 +261,7 @@ func handleInstallConfigure(w http.ResponseWriter, r *http.Request) {
|
||||
// until all requests are finished, and _we_ are inside a request right now, so it will block indefinitely
|
||||
if restartHTTP {
|
||||
go func() {
|
||||
config.httpServer.Shutdown(context.TODO())
|
||||
_ = config.httpServer.Shutdown(context.TODO())
|
||||
}()
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,9 @@ func onConfigModified() {
|
||||
// initDNSServer creates an instance of the dnsforward.Server
|
||||
// Please note that we must do it even if we don't start it
|
||||
// so that we had access to the query log and the stats
|
||||
func initDNSServer(baseDir string) {
|
||||
func initDNSServer() {
|
||||
baseDir := config.getDataDir()
|
||||
|
||||
err := os.MkdirAll(baseDir, 0755)
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot create DNS data dir at %s: %s", baseDir, err)
|
||||
@ -52,7 +54,7 @@ func initDNSServer(baseDir string) {
|
||||
config.queryLog = querylog.New(conf)
|
||||
config.dnsServer = dnsforward.NewServer(config.stats, config.queryLog)
|
||||
|
||||
sessFilename := filepath.Join(config.ourWorkingDir, "data/sessions.db")
|
||||
sessFilename := filepath.Join(baseDir, "sessions.db")
|
||||
config.auth = InitAuth(sessFilename, config.Users)
|
||||
config.Users = nil
|
||||
|
||||
@ -65,6 +67,7 @@ func isRunning() bool {
|
||||
return config.dnsServer != nil && config.dnsServer.IsRunning()
|
||||
}
|
||||
|
||||
// nolint (gocyclo)
|
||||
// Return TRUE if IP is within public Internet IP range
|
||||
func isPublicIP(ip net.IP) bool {
|
||||
ip4 := ip.To4()
|
||||
|
@ -1,12 +1,16 @@
|
||||
package home
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestResolveRDNS(t *testing.T) {
|
||||
_ = os.RemoveAll(config.getDataDir())
|
||||
defer func() { _ = os.RemoveAll(config.getDataDir()) }()
|
||||
|
||||
config.DNS.BindHost = "1.1.1.1"
|
||||
initDNSServer(".")
|
||||
initDNSServer()
|
||||
if r := config.dnsctx.rdns.resolve("1.1.1.1"); r != "one.one.one.one" {
|
||||
t.Errorf("resolveRDNS(): %s", r)
|
||||
}
|
||||
|
@ -448,7 +448,7 @@ func (filter *filter) unload() {
|
||||
|
||||
// Path to the filter contents
|
||||
func (filter *filter) Path() string {
|
||||
return filepath.Join(config.ourWorkingDir, dataDir, filterDir, strconv.FormatInt(filter.ID, 10)+".txt")
|
||||
return filepath.Join(config.getDataDir(), filterDir, strconv.FormatInt(filter.ID, 10)+".txt")
|
||||
}
|
||||
|
||||
// LastTimeUpdated returns the time when the filter was last time updated
|
||||
|
@ -142,8 +142,7 @@ func run(args options) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir)
|
||||
initDNSServer(dnsBaseDir)
|
||||
initDNSServer()
|
||||
|
||||
err = startDNSServer()
|
||||
if err != nil {
|
||||
|
@ -271,7 +271,7 @@ func (r *Reader) BeginReadPrev(olderThan time.Time, count uint64) {
|
||||
if int64(off) < maxEntrySize {
|
||||
off = 0
|
||||
}
|
||||
r.fpos = uint64(off)
|
||||
r.fpos = off
|
||||
log.Debug("QueryLog: seek: %x", off)
|
||||
_, err := r.f.Seek(int64(off), io.SeekStart)
|
||||
if err != nil {
|
||||
@ -376,7 +376,7 @@ func (r *Reader) prepareRead() bool {
|
||||
if int64(off) < maxEntrySize {
|
||||
off = 0
|
||||
}
|
||||
r.fpos = uint64(off)
|
||||
r.fpos = off
|
||||
log.Debug("QueryLog: seek: %x", off)
|
||||
_, err = r.f.Seek(int64(off), io.SeekStart)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user