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
|
||||||
/querylog.json.1
|
/querylog.json.1
|
||||||
/a_main-packr.go
|
/a_main-packr.go
|
||||||
|
coverage.txt
|
||||||
|
|
||||||
# Test output
|
# Test output
|
||||||
dnsfilter/tests/top-1m.csv
|
dnsfilter/tests/top-1m.csv
|
||||||
dnsfilter/tests/dnsfilter.TestLotsOfRules*.pprof
|
dnsfilter/tests/dnsfilter.TestLotsOfRules*.pprof
|
||||||
|
@ -38,6 +38,9 @@ linters:
|
|||||||
- gochecknoinits
|
- gochecknoinits
|
||||||
- prealloc
|
- prealloc
|
||||||
- maligned
|
- maligned
|
||||||
|
- godox
|
||||||
|
- funlen
|
||||||
|
- whitespace
|
||||||
- goconst # disabled until it's possible to configure
|
- goconst # disabled until it's possible to configure
|
||||||
fast: true
|
fast: true
|
||||||
|
|
||||||
|
10
.travis.yml
10
.travis.yml
@ -3,7 +3,6 @@ sudo: false
|
|||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.12.x
|
- 1.12.x
|
||||||
- 1.x
|
|
||||||
os:
|
os:
|
||||||
- linux
|
- linux
|
||||||
- osx
|
- osx
|
||||||
@ -11,6 +10,7 @@ os:
|
|||||||
before_install:
|
before_install:
|
||||||
- nvm install node
|
- nvm install node
|
||||||
- npm install -g npm
|
- 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:
|
install:
|
||||||
- npm --prefix client install
|
- npm --prefix client install
|
||||||
@ -22,13 +22,7 @@ cache:
|
|||||||
- $HOME/Library/Caches/go-build
|
- $HOME/Library/Caches/go-build
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- node -v
|
- /bin/bash ci.sh
|
||||||
- npm -v
|
|
||||||
# Run tests
|
|
||||||
- go test -race -v -bench=. -coverprofile=coverage.txt -covermode=atomic ./...
|
|
||||||
# Make
|
|
||||||
- make build/static/index.html
|
|
||||||
- make
|
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
- 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 (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -10,13 +11,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestAuth(t *testing.T) {
|
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{
|
users := []User{
|
||||||
User{Name: "name", PasswordHash: "$2y$05$..vyzAECIhJPfaQiOK17IukcQnqEgKJHy0iETyYqxn3YXJl8yZuo2"},
|
User{Name: "name", PasswordHash: "$2y$05$..vyzAECIhJPfaQiOK17IukcQnqEgKJHy0iETyYqxn3YXJl8yZuo2"},
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Remove(fn)
|
os.MkdirAll(config.getDataDir(), 0755)
|
||||||
config.ourWorkingDir = "."
|
|
||||||
a := InitAuth(fn, users)
|
a := InitAuth(fn, users)
|
||||||
|
|
||||||
assert.True(t, a.CheckSession("notfound") == -1)
|
assert.True(t, a.CheckSession("notfound") == -1)
|
||||||
|
@ -239,6 +239,11 @@ func (c *configuration) getConfigFilename() string {
|
|||||||
return configFile
|
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.
|
// 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.
|
// we do it in a separate method in order to configure logger before the actual configuration is parsed and applied.
|
||||||
func getLogSettings() logSettings {
|
func getLogSettings() logSettings {
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"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.BindHost = newSettings.DNS.IP
|
||||||
config.DNS.Port = newSettings.DNS.Port
|
config.DNS.Port = newSettings.DNS.Port
|
||||||
|
|
||||||
dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir)
|
initDNSServer()
|
||||||
initDNSServer(dnsBaseDir)
|
|
||||||
|
|
||||||
err = startDNSServer()
|
err = startDNSServer()
|
||||||
if err != nil {
|
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
|
// until all requests are finished, and _we_ are inside a request right now, so it will block indefinitely
|
||||||
if restartHTTP {
|
if restartHTTP {
|
||||||
go func() {
|
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
|
// initDNSServer creates an instance of the dnsforward.Server
|
||||||
// Please note that we must do it even if we don't start it
|
// 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
|
// 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)
|
err := os.MkdirAll(baseDir, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Cannot create DNS data dir at %s: %s", baseDir, err)
|
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.queryLog = querylog.New(conf)
|
||||||
config.dnsServer = dnsforward.NewServer(config.stats, config.queryLog)
|
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.auth = InitAuth(sessFilename, config.Users)
|
||||||
config.Users = nil
|
config.Users = nil
|
||||||
|
|
||||||
@ -65,6 +67,7 @@ func isRunning() bool {
|
|||||||
return config.dnsServer != nil && config.dnsServer.IsRunning()
|
return config.dnsServer != nil && config.dnsServer.IsRunning()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint (gocyclo)
|
||||||
// Return TRUE if IP is within public Internet IP range
|
// Return TRUE if IP is within public Internet IP range
|
||||||
func isPublicIP(ip net.IP) bool {
|
func isPublicIP(ip net.IP) bool {
|
||||||
ip4 := ip.To4()
|
ip4 := ip.To4()
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
package home
|
package home
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResolveRDNS(t *testing.T) {
|
func TestResolveRDNS(t *testing.T) {
|
||||||
|
_ = os.RemoveAll(config.getDataDir())
|
||||||
|
defer func() { _ = os.RemoveAll(config.getDataDir()) }()
|
||||||
|
|
||||||
config.DNS.BindHost = "1.1.1.1"
|
config.DNS.BindHost = "1.1.1.1"
|
||||||
initDNSServer(".")
|
initDNSServer()
|
||||||
if r := config.dnsctx.rdns.resolve("1.1.1.1"); r != "one.one.one.one" {
|
if r := config.dnsctx.rdns.resolve("1.1.1.1"); r != "one.one.one.one" {
|
||||||
t.Errorf("resolveRDNS(): %s", r)
|
t.Errorf("resolveRDNS(): %s", r)
|
||||||
}
|
}
|
||||||
|
@ -448,7 +448,7 @@ func (filter *filter) unload() {
|
|||||||
|
|
||||||
// Path to the filter contents
|
// Path to the filter contents
|
||||||
func (filter *filter) Path() string {
|
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
|
// LastTimeUpdated returns the time when the filter was last time updated
|
||||||
|
@ -142,8 +142,7 @@ func run(args options) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir)
|
initDNSServer()
|
||||||
initDNSServer(dnsBaseDir)
|
|
||||||
|
|
||||||
err = startDNSServer()
|
err = startDNSServer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -271,7 +271,7 @@ func (r *Reader) BeginReadPrev(olderThan time.Time, count uint64) {
|
|||||||
if int64(off) < maxEntrySize {
|
if int64(off) < maxEntrySize {
|
||||||
off = 0
|
off = 0
|
||||||
}
|
}
|
||||||
r.fpos = uint64(off)
|
r.fpos = off
|
||||||
log.Debug("QueryLog: seek: %x", off)
|
log.Debug("QueryLog: seek: %x", off)
|
||||||
_, err := r.f.Seek(int64(off), io.SeekStart)
|
_, err := r.f.Seek(int64(off), io.SeekStart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -376,7 +376,7 @@ func (r *Reader) prepareRead() bool {
|
|||||||
if int64(off) < maxEntrySize {
|
if int64(off) < maxEntrySize {
|
||||||
off = 0
|
off = 0
|
||||||
}
|
}
|
||||||
r.fpos = uint64(off)
|
r.fpos = off
|
||||||
log.Debug("QueryLog: seek: %x", off)
|
log.Debug("QueryLog: seek: %x", off)
|
||||||
_, err = r.f.Seek(int64(off), io.SeekStart)
|
_, err = r.f.Seek(int64(off), io.SeekStart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user