New Upstream Release - golang-gopkg-jcmturner-dnsutils.v1
Ready changes
Summary
Merged new upstream version: 2.0.0 (was: 1.0.1).
Resulting package
Built on 2023-01-27T14:02 (took 1m56s)
The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:
apt install -t fresh-releases golang-gopkg-jcmturner-dnsutils.v1-dev
Lintian Result
Diff
diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml
new file mode 100644
index 0000000..7565a92
--- /dev/null
+++ b/.github/workflows/testing.yml
@@ -0,0 +1,83 @@
+name: v1
+on:
+ push:
+ paths-ignore:
+ - 'v[0-9]+/**'
+ pull_request:
+ paths-ignore:
+ - 'v[0-9]+/**'
+
+jobs:
+ build:
+ name: Tests
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ go: [ '1.11.x', '1.12.x', '1.13.x' ]
+ env:
+ TEST_KDC_ADDR: 127.0.0.1
+ TEST_HTTP_URL: http://cname.test.gokrb5
+ TEST_HTTP_ADDR: 127.0.0.1
+ DNS_IP: 127.0.88.53
+ DNSUTILS_OVERRIDE_NS: 127.0.88.53:53
+ steps:
+ - name: Set up Go ${{ matrix.go }}
+ uses: actions/setup-go@v1
+ with:
+ go-version: ${{ matrix.go }}
+
+ - name: Checkout
+ uses: actions/checkout@v2
+ with:
+ ref: ${{ github.ref }}
+
+ - name: Test well formatted with gofmt
+ run: |
+ # Remove major version sub directories
+ find . -maxdepth 1 -type d -regex '\./v[0-9]+' | xargs -i rm -rf {}
+ GO_FILES=$(find . -iname '*.go' -type f | grep -v /vendor/)
+ test -z $(gofmt -s -d -l -e $GO_FILES | tee /dev/fd/2 | xargs | sed 's/\s//g')
+ id: gofmt
+
+ - name: Copy into GOPATH
+ run: |
+ # Default GOPATH=${HOME}/go
+ mkdir -p ${HOME}/go/src/github.com/${GITHUB_REPOSITORY}
+ cp -r $GITHUB_WORKSPACE/* /home/runner/go/src/github.com/${GITHUB_REPOSITORY}
+ id: copyToGOPATH
+
+ - name: Get dependencies
+ run: |
+ cd ${HOME}/go/src/github.com/${GITHUB_REPOSITORY}
+ go get -v -t -d ./...
+ id: goGet
+
+ - name: Go vet
+ run: |
+ cd ${HOME}/go/src/github.com/${GITHUB_REPOSITORY}
+ go vet $(go list ./... | grep -E -v '/v[0-9]+' | grep -v /vendor/)
+ id: govet
+
+ - name: Start integration test dependencies
+ run: |
+ sudo docker run -d -h ns.test.gokrb5 -v /etc/localtime:/etc/localtime:ro -e "TEST_KDC_ADDR=${TEST_KDC_ADDR}" -e "TEST_HTTP_ADDR=${TEST_HTTP_ADDR}" -p ${DNSUTILS_OVERRIDE_NS}:53 -p ${DNSUTILS_OVERRIDE_NS}:53/udp --name dns jcmturner/gokrb5:dns
+ sudo sed -i 's/nameserver .*/nameserver '${DNS_IP}'/g' /etc/resolv.conf
+ dig _kerberos._udp.TEST.GOKRB5
+ id: intgTestDeps
+
+ - name: Unit tests
+ run: |
+ cd ${HOME}/go/src/github.com/${GITHUB_REPOSITORY}
+ go test -race $(go list ./... | grep -E -v '/v[0-9]+' | grep -v /vendor/)
+ env:
+ INTEGRATION: 1
+ id: unitTests
+
+ - name: Unit tests (32bit)
+ run: |
+ cd ${HOME}/go/src/github.com/${GITHUB_REPOSITORY}
+ go test $(go list ./... | grep -E -v '/v[0-9]+' | grep -v /vendor/)
+ env:
+ GOARCH: 386
+ INTEGRATION: 1
+ id: unitTest32
\ No newline at end of file
diff --git a/.github/workflows/testingv2.yml b/.github/workflows/testingv2.yml
new file mode 100644
index 0000000..8dc53fd
--- /dev/null
+++ b/.github/workflows/testingv2.yml
@@ -0,0 +1,69 @@
+# Name of the workflow needs to match the name of the major version directory
+name: v2
+on:
+ push:
+ paths:
+ - 'v2/**'
+ pull_request:
+ paths:
+ - 'v2/**'
+
+jobs:
+ build:
+ name: Tests
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ go: [ '1.11.x', '1.12.x', '1.13.x' ]
+ env:
+ TEST_KDC_ADDR: 127.0.0.1
+ TEST_HTTP_URL: http://cname.test.gokrb5
+ TEST_HTTP_ADDR: 127.0.0.1
+ DNS_IP: 127.0.88.53
+ DNSUTILS_OVERRIDE_NS: 127.0.88.53:53
+ steps:
+ - name: Set up Go ${{ matrix.go }}
+ uses: actions/setup-go@v1
+ with:
+ go-version: ${{ matrix.go }}
+
+ - name: Checkout
+ uses: actions/checkout@v2
+ with:
+ ref: ${{ github.ref }}
+
+ - name: Test well formatted with gofmt
+ run: |
+ GO_FILES=$(find ${GITHUB_WORKFLOW} -iname '*.go' -type f | grep -v /vendor/)
+ test -z $(gofmt -s -d -l -e $GO_FILES | tee /dev/fd/2 | xargs | sed 's/\s//g')
+ id: gofmt
+
+ - name: Go vet
+ run: |
+ cd ${GITHUB_WORKFLOW}
+ go vet ./...
+ id: govet
+
+ - name: Start integration test dependencies
+ run: |
+ sudo docker run -d -h ns.test.gokrb5 -v /etc/localtime:/etc/localtime:ro -e "TEST_KDC_ADDR=${TEST_KDC_ADDR}" -e "TEST_HTTP_ADDR=${TEST_HTTP_ADDR}" -p ${DNSUTILS_OVERRIDE_NS}:53 -p ${DNSUTILS_OVERRIDE_NS}:53/udp --name dns jcmturner/gokrb5:dns
+ sudo sed -i 's/nameserver .*/nameserver '${DNS_IP}'/g' /etc/resolv.conf
+ dig _kerberos._udp.TEST.GOKRB5
+ id: intgTestDeps
+
+ - name: Unit tests
+ run: |
+ cd ${GITHUB_WORKFLOW}
+ go test -race ./...
+ env:
+ INTEGRATION: 1
+ id: unitTests
+
+ - name: Unit tests (32bit)
+ run: |
+ cd ${GITHUB_WORKFLOW}
+ go test ./...
+ env:
+ GOARCH: 386
+ INTEGRATION: 1
+ id: unitTest32
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index cab4f7b..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-language: go
-
-go:
- - 1.7.x
- - 1.8.x
- - 1.9.x
- - master
-
-gobuild_args: -tags=integration -race
-
-sudo: required
-
-services:
- - docker
-
-before_install:
- - docker pull jcmturner/gokrb5:dns
- - docker run -d -h kdc.test.gokrb5 -v /etc/localtime:/etc/localtime:ro -e "TEST_KDC_ADDR=127.0.0.1" -p 53:53 -p 53:53/udp --name dns jcmturner/gokrb5:dns
-
-before_script:
- - sudo sed -i 's/nameserver .*/nameserver 127.0.0.1/g' /etc/resolv.conf
-
-env:
- - DNSUTILS_OVERRIDE_NS="127.0.0.1:53"
\ No newline at end of file
diff --git a/debian/changelog b/debian/changelog
index d52f71e..68e48ca 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-gopkg-jcmturner-dnsutils.v1 (2.0.0-1) UNRELEASED; urgency=low
+
+ * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk> Fri, 27 Jan 2023 14:00:28 -0000
+
golang-gopkg-jcmturner-dnsutils.v1 (1.0.1-2) unstable; urgency=medium
* Reupload as source-only
diff --git a/srv_integration_test.go b/srv_integration_test.go
index 6ba8f51..66a7c29 100644
--- a/srv_integration_test.go
+++ b/srv_integration_test.go
@@ -1,16 +1,17 @@
-// +build integration
-// To turn on this test use -tags=integration in go test command
-
package dnsutils
import (
"github.com/stretchr/testify/assert"
+ "os"
"strconv"
"strings"
"testing"
)
func TestResolveKDC(t *testing.T) {
+ if os.Getenv("INTEGRATION") != "1" {
+ t.Skip("Skipping integration test")
+ }
for i := 0; i < 100; i++ {
count, res, err := OrderedSRV("kerberos", "tcp", "test.gokrb5")
if err != nil {
diff --git a/v2/go.mod b/v2/go.mod
new file mode 100644
index 0000000..f75ac6d
--- /dev/null
+++ b/v2/go.mod
@@ -0,0 +1,5 @@
+module github.com/jcmturner/dnsutils/v2
+
+go 1.13
+
+require github.com/stretchr/testify v1.4.0
diff --git a/v2/go.sum b/v2/go.sum
new file mode 100644
index 0000000..e863f51
--- /dev/null
+++ b/v2/go.sum
@@ -0,0 +1,10 @@
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/v2/srv.go b/v2/srv.go
new file mode 100644
index 0000000..15ea912
--- /dev/null
+++ b/v2/srv.go
@@ -0,0 +1,95 @@
+package dnsutils
+
+import (
+ "math/rand"
+ "net"
+ "sort"
+)
+
+// OrderedSRV returns a count of the results and a map keyed on the order they should be used.
+// This based on the records' priority and randomised selection based on their relative weighting.
+// The function's inputs are the same as those for net.LookupSRV
+// To use in the correct order:
+//
+// count, orderedSRV, err := OrderedSRV(service, proto, name)
+// i := 1
+// for i <= count {
+// srv := orderedSRV[i]
+// // Do something such as dial this SRV. If fails move on the the next or break if it succeeds.
+// i += 1
+// }
+func OrderedSRV(service, proto, name string) (int, map[int]*net.SRV, error) {
+ _, addrs, err := net.LookupSRV(service, proto, name)
+ if err != nil {
+ return 0, make(map[int]*net.SRV), err
+ }
+ index, osrv := orderSRV(addrs)
+ return index, osrv, nil
+}
+
+func orderSRV(addrs []*net.SRV) (int, map[int]*net.SRV) {
+ // Initialise the ordered map
+ var o int
+ osrv := make(map[int]*net.SRV)
+
+ prioMap := make(map[int][]*net.SRV, 0)
+ for _, srv := range addrs {
+ prioMap[int(srv.Priority)] = append(prioMap[int(srv.Priority)], srv)
+ }
+
+ priorities := make([]int, 0)
+ for p := range prioMap {
+ priorities = append(priorities, p)
+ }
+
+ var count int
+ sort.Ints(priorities)
+ for _, p := range priorities {
+ tos := weightedOrder(prioMap[p])
+ for i, s := range tos {
+ count += 1
+ osrv[o+i] = s
+ }
+ o += len(tos)
+ }
+ return count, osrv
+}
+
+func weightedOrder(srvs []*net.SRV) map[int]*net.SRV {
+ // Get the total weight
+ var tw int
+ for _, s := range srvs {
+ tw += int(s.Weight)
+ }
+
+ // Initialise the ordered map
+ o := 1
+ osrv := make(map[int]*net.SRV)
+
+ // Whilst there are still entries to be ordered
+ l := len(srvs)
+ for l > 0 {
+ i := rand.Intn(l)
+ s := srvs[i]
+ var rw int
+ if tw > 0 {
+ // Greater the weight the more likely this will be zero or less
+ rw = rand.Intn(tw) - int(s.Weight)
+ }
+ if rw <= 0 {
+ // Put entry in position
+ osrv[o] = s
+ if len(srvs) > 1 {
+ // Remove the entry from the source slice by swapping with the last entry and truncating
+ srvs[len(srvs)-1], srvs[i] = srvs[i], srvs[len(srvs)-1]
+ srvs = srvs[:len(srvs)-1]
+ l = len(srvs)
+ } else {
+ l = 0
+ }
+ o += 1
+ tw = tw - int(s.Weight)
+ }
+ }
+ return osrv
+}
diff --git a/v2/srv_integration_test.go b/v2/srv_integration_test.go
new file mode 100644
index 0000000..72e8472
--- /dev/null
+++ b/v2/srv_integration_test.go
@@ -0,0 +1,41 @@
+package dnsutils
+
+import (
+ "github.com/stretchr/testify/assert"
+ "os"
+ "strconv"
+ "strings"
+ "testing"
+)
+
+func TestResolveKDC(t *testing.T) {
+ if os.Getenv("INTEGRATION") != "1" {
+ t.Skip("Skipping integration test.")
+ }
+ for i := 0; i < 100; i++ {
+ count, res, err := OrderedSRV("kerberos", "tcp", "test.gokrb5")
+ if err != nil {
+ t.Errorf("error resolving SRV DNS records: %v", err)
+ }
+ expected := []string{
+ "kdc.test.gokrb5:88",
+ "kdc1a.test.gokrb5:88",
+ "kdc2a.test.gokrb5:88",
+ "kdc1b.test.gokrb5:88",
+ "kdc2b.test.gokrb5:88",
+ }
+ assert.Equal(t, len(expected), count, "Number of SRV records not as expected: %v", res)
+ assert.Equal(t, count, len(res), "Map size does not match: %v", res)
+ for _, s := range expected {
+ var found bool
+ for _, v := range res {
+ srvStr := strings.TrimRight(v.Target, ".") + ":" + strconv.Itoa(int(v.Port))
+ if s == srvStr {
+ found = true
+ break
+ }
+ }
+ assert.True(t, found, "Record %s not found in results", s)
+ }
+ }
+}
diff --git a/v2/srv_test.go b/v2/srv_test.go
new file mode 100644
index 0000000..4596b34
--- /dev/null
+++ b/v2/srv_test.go
@@ -0,0 +1,42 @@
+package dnsutils
+
+import (
+ "github.com/stretchr/testify/assert"
+ "net"
+ "testing"
+)
+
+func TestOrderSRV(t *testing.T) {
+ srv11 := net.SRV{
+ Target: "t11",
+ Port: 1234,
+ Priority: 1,
+ Weight: 100,
+ }
+ srv12 := net.SRV{
+ Target: "t12",
+ Port: 1234,
+ Priority: 1,
+ Weight: 100,
+ }
+ srv13 := net.SRV{
+ Target: "t13",
+ Port: 1234,
+ Priority: 1,
+ Weight: 20,
+ }
+ srv21 := net.SRV{
+ Target: "t21",
+ Port: 1234,
+ Priority: 2,
+ Weight: 1,
+ }
+
+ addrs := []*net.SRV{
+ &srv11, &srv21, &srv12, &srv13,
+ }
+ count, orderedSRV := orderSRV(addrs)
+ assert.Equal(t, len(addrs), count, "Index not the expected size")
+ assert.Equal(t, len(addrs), len(orderedSRV), "orderedSRV not the expected size")
+ assert.Equal(t, uint16(2), orderedSRV[4].Priority, "Priority order not as expected")
+}
Debdiff
[The following lists of changes regard files as different if they have different names, permissions or owners.]
Files in second set of .debs but not in first
-rw-r--r-- root/root /usr/share/gocode/src/gopkg.in/jcmturner/dnsutils.v1/v2/srv.go -rw-r--r-- root/root /usr/share/gocode/src/gopkg.in/jcmturner/dnsutils.v1/v2/srv_integration_test.go -rw-r--r-- root/root /usr/share/gocode/src/gopkg.in/jcmturner/dnsutils.v1/v2/srv_test.go
No differences were encountered in the control files