Skip to content

Commit 7c72fe6

Browse files
authored
Release 2.0.1 (#20)
* ci: merged lint into ci-test.yml * ci: depend on GHA shared workflows - fix: when adding headers, assure ASN is string - fix: when adding header, look in correct location for asn.org - when create conn note, only assign properties with values
1 parent db58a0a commit 7c72fe6

11 files changed

+86
-140
lines changed

.codeclimate.yml

+5
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ engines:
88
ratings:
99
paths:
1010
- "**.js"
11+
12+
checks:
13+
method-complexity:
14+
config:
15+
threshold: 10
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
1-
name: Tests
1+
name: CI
22

3-
on: [ push ]
3+
on:
4+
push:
45

56
env:
67
CI: true
78

89
jobs:
10+
lint:
11+
uses: haraka/.github/.github/workflows/lint.yml@master
912

10-
ci-test:
13+
# coverage:
14+
# uses: haraka/.github/.github/workflows/coverage.yml@master
15+
# secrets: inherit
1116

17+
test:
18+
needs: lint
1219
runs-on: ${{ matrix.os }}
13-
1420
strategy:
1521
matrix:
1622
os: [ ubuntu-latest, windows-latest ]
1723
node-version: [ 14, 16, 18 ]
1824
fail-fast: false
1925

2026
steps:
21-
- uses: actions/checkout@v2
27+
- uses: actions/checkout@v3
28+
2229
- uses: actions/setup-node@v3
2330
name: Node ${{ matrix.node-version }} on ${{ matrix.os }}
2431
with:
2532
node-version: ${{ matrix.node-version }}
2633

2734
- run: npm install
35+
2836
- run: npm test

.github/workflows/codeql.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: CodeQL
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
# The branches below must be a subset of the branches above
8+
branches: [ master ]
9+
schedule:
10+
- cron: '18 7 * * 4'
11+
12+
jobs:
13+
codeql:
14+
uses: haraka/.github/.github/workflows/codeql.yml@master

.github/workflows/coveralls.yml

-32
This file was deleted.

.github/workflows/lint.yml

-23
This file was deleted.

.github/workflows/publish.yml

+10-43
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,16 @@
1-
name: Publish
1+
name: publish
22

33
on:
4-
release:
5-
types: [ published ]
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- package.json
69

710
env:
8-
node_version: 16
11+
CI: true
912

1013
jobs:
11-
12-
build:
13-
runs-on: ubuntu-latest
14-
steps:
15-
- uses: actions/checkout@v2
16-
- uses: actions/setup-node@v3
17-
with:
18-
node-version: ${{ env.node_version }}
19-
- run: npm install
20-
- run: npm test
21-
22-
publish-npm:
23-
needs: build
24-
runs-on: ubuntu-latest
25-
steps:
26-
- uses: actions/checkout@v2
27-
28-
- uses: actions/setup-node@v3
29-
with:
30-
node-version: ${{ env.node_version }}
31-
registry-url: https://registry.npmjs.org
32-
- run: npm install
33-
34-
- run: npm publish --ignore-scripts --access public
35-
env:
36-
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
37-
38-
publish-gpr:
39-
needs: build
40-
runs-on: ubuntu-latest
41-
steps:
42-
- name: Checkout
43-
uses: actions/checkout@v2
44-
45-
- uses: actions/setup-node@v2
46-
with:
47-
node-version: ${{ env.node_version }}
48-
registry-url: https://registry.npmjs.org
49-
- run: npm install
14+
publish:
15+
uses: haraka/.github/.github/workflows/publish.yml@master
16+
secrets: inherit

Changes.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11

2+
## 2.0.1 - 2022-05-27
3+
4+
- fix: when adding headers, assure ASN is string
5+
- fix: when adding header, look in correct location for asn.org
6+
- when create conn note, only assign properties with values
7+
28

39
## 2.0.0 - 2022-05-23
410

511
- style: replace most callbacks with async/await
612
- use builtin/promises where available
13+
- asn.ini: switch default dns provider to rspamd
14+
- dep: remove async
715

816

917
## 1.0.9 - 2022-05-22

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ look up ASN from local GeoIP databases and/or DNS based providers.
2121
PS: Run something like [maxmind-geolite-mirror](https://www.npmjs.com/package/maxmind-geolite-mirror) weekly to keep your database files up-to-date.
2222

2323

24-
[ci-img]: https://github.com/haraka/haraka-plugin-asn/actions/workflows/ci-test.yml/badge.svg
25-
[ci-url]: https://github.com/haraka/haraka-plugin-asn/actions/workflows/ci-test.yml
26-
[cov-img]: https://codecov.io/github/haraka/haraka-plugin-asn/badge.svg
27-
[cov-url]: https://codecov.io/github/haraka/haraka-plugin-asn
24+
[ci-img]: https://github.com/haraka/haraka-plugin-asn/actions/workflows/ci.yml/badge.svg
25+
[ci-url]: https://github.com/haraka/haraka-plugin-asn/actions/workflows/ci.yml
2826
[clim-img]: https://codeclimate.com/github/haraka/haraka-plugin-asn/badges/gpa.svg
2927
[clim-url]: https://codeclimate.com/github/haraka/haraka-plugin-asn
3028
[npm-img]: https://nodei.co/npm/haraka-plugin-asn.png

index.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,17 @@ exports.parse_rspamd = function (str) {
247247
exports.add_header_asn = function (next, connection) {
248248

249249
const asn = connection.results.get('asn');
250-
if (!asn || !asn.asn) return next();
251-
250+
if (!asn?.asn) return next();
252251
if (!connection.transaction) return next();
253252

254253
if (asn.net) {
255254
connection.transaction.add_header('X-Haraka-ASN', `${asn.asn} ${asn.net}`);
256255
}
257256
else {
258-
connection.transaction.add_header('X-Haraka-ASN', asn.asn);
257+
connection.transaction.add_header('X-Haraka-ASN', `${asn.asn}`);
259258
}
260-
if (asn.asn_org) {
261-
connection.transaction.add_header('X-Haraka-ASN-Org', asn.asn_org);
259+
if (asn.org) {
260+
connection.transaction.add_header('X-Haraka-ASN-Org', `${asn.org}`);
262261
}
263262

264263
next();
@@ -267,7 +266,7 @@ exports.add_header_asn = function (next, connection) {
267266
exports.add_header_provider = function (next, connection) {
268267

269268
const asn = connection.results.get('asn');
270-
if (!asn || !asn.asn) return next();
269+
if (!asn?.asn) return next();
271270

272271
for (const p in asn) {
273272
if (!asn[p].asn) continue; // ignore non-object results
@@ -307,7 +306,7 @@ exports.load_dbs = async function () {
307306
try {
308307
await fs.access(dbPath)
309308

310-
this.ASNLookup = await this.maxmind.open(dbPath, {
309+
this.lookup = await this.maxmind.open(dbPath, {
311310
// this causes tests to hang, which is why mocha runs with --exit
312311
watchForUpdates: true,
313312
cache: {
@@ -320,6 +319,7 @@ exports.load_dbs = async function () {
320319
this.dbsLoaded++;
321320
}
322321
catch (e) {
322+
console.error(e)
323323
this.loginfo(`missing [access to] DB ${dbPath}`)
324324
}
325325

@@ -329,11 +329,11 @@ exports.load_dbs = async function () {
329329
exports.lookup_via_maxmind = function (next, connection) {
330330
if (!this.maxmind || !this.dbsLoaded) return next();
331331

332-
const asn = this.ASNLookup.get(connection.remote.ip)
333-
if (asn) {
332+
const asn = this.lookup.get(connection.remote.ip)
333+
if (asn?.autonomous_system_number || asn?.autonomous_system_organization) {
334334
connection.results.add(this, {
335-
asn: asn.autonomous_system_number,
336-
org: asn.autonomous_system_organization,
335+
...(asn.autonomous_system_number ? { asn: asn.autonomous_system_number } : {}),
336+
...(asn.autonomous_system_organization ? { org: asn.autonomous_system_organization } : {}),
337337
});
338338
}
339339

package.json

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
22
"name": "haraka-plugin-asn",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "look up ASN of remote MTA",
55
"main": "index.js",
66
"scripts": {
77
"test": "npx mocha --exit",
8-
"lint": "npx eslint *.js test/*.js",
9-
"lintfix": "npx eslint --fix *.js test/*.js",
10-
"coverage": "npx istanbul cover npm test",
8+
"lint": "npx eslint *.js test",
9+
"lintfix": "npx eslint --fix *.js test",
1110
"versions": "npx dependency-version-checker check"
1211
},
1312
"repository": {
@@ -31,8 +30,8 @@
3130
},
3231
"devDependencies": {
3332
"eslint": ">=8",
34-
"eslint-plugin-haraka": ">=1.0.5",
35-
"haraka-test-fixtures": ">=1.0.30",
36-
"mocha": "*"
33+
"eslint-plugin-haraka": ">=1.0.14",
34+
"haraka-test-fixtures": ">=1.0.34",
35+
"mocha": ">=9"
3736
}
3837
}

test/asn.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ describe('maxmind geoip db', () => {
189189
asn.test_and_register_geoip().then((r) => {
190190
// console.log(r)
191191
assert.ok(asn.maxmind)
192-
// assert.ok(asn.ASNLookup)
193-
// console.log(asn.ASNLookup)
194192
done()
195193
})
196194
})
@@ -216,23 +214,27 @@ describe('maxmind geoip db', () => {
216214
})
217215
})
218216

219-
it('maxmind AS w/o org', (done) => {
217+
it('maxmind AS with org', (done) => {
220218
const asn = new fixtures.plugin('asn');
221219
asn.cfg = { main: { }, protocols: { geoip: true } };
222220
asn.connection = fixtures.connection.createConnection();
223-
asn.connection.remote.ip='216.255.64.1';
221+
asn.connection.remote.ip='1.1.1.1';
224222
asn.test_and_register_geoip().then(() => {
225-
226-
asn.lookup_via_maxmind(() => {
227-
if (asn.mmDbsAvail && asn.mmDbsAvail.length > 0) {
228-
const res = asn.connection.results.get('asn');
229-
// console.log(res);
230-
assert.equal(res.asn, 63200);
231-
assert.equal(res.org, '');
232-
}
233-
done();
234-
},
235-
asn.connection);
223+
try {
224+
asn.lookup_via_maxmind(() => {
225+
if (asn.dbsLoaded) {
226+
const res = asn.connection.results.get('asn');
227+
assert.equal(res?.asn, 13335);
228+
assert.equal(res?.org, 'CLOUDFLARENET');
229+
}
230+
done()
231+
},
232+
asn.connection);
233+
}
234+
catch (e) {
235+
console.error(e)
236+
done()
237+
}
236238
})
237239
})
238240
})

0 commit comments

Comments
 (0)