mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-08-11 14:22:41 +00:00
Merge branch 'main' into main
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
name: Checks
|
||||
on: [pull_request]
|
||||
on: [pull_request, workflow_dispatch]
|
||||
|
||||
jobs:
|
||||
validation:
|
||||
@@ -9,15 +9,8 @@ jobs:
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
fetch-depth: 0
|
||||
- name: Setup node v16
|
||||
uses: actions/setup-node@v1
|
||||
- uses: oven-sh/setup-bun@v1
|
||||
with:
|
||||
node-version: '16'
|
||||
- name: Install dependencies
|
||||
uses: borales/actions-yarn@v2.0.0
|
||||
with:
|
||||
cmd: install --ignore-engines --frozen-lockfile
|
||||
- name: Run tests
|
||||
uses: borales/actions-yarn@v2.0.0
|
||||
with:
|
||||
cmd: test
|
||||
bun-version: 1.0.0
|
||||
- run: bun install
|
||||
- run: bun test
|
||||
|
||||
@@ -12,16 +12,15 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: borales/actions-yarn@v2.0.0
|
||||
- uses: oven-sh/setup-bun@v1
|
||||
with:
|
||||
cmd: install --ignore-engines
|
||||
- name: Running tests
|
||||
uses: borales/actions-yarn@v2.0.0
|
||||
with:
|
||||
cmd: test
|
||||
bun-version: 1.0.0
|
||||
- run: bun install
|
||||
- run: bun test
|
||||
- name: Publishing records
|
||||
env:
|
||||
CI: 1
|
||||
NODE_ENV: production
|
||||
ENV: production
|
||||
DOMAIN_USER: ${{ secrets.DOMAIN_USER }}
|
||||
DOMAIN_API_KEY: ${{ secrets.DOMAIN_API_KEY }}
|
||||
@@ -29,6 +28,4 @@ jobs:
|
||||
DOMAIN_API_PORT: ${{ secrets.DOMAIN_API_PORT }}
|
||||
DOMAIN_DOMAIN: ${{ secrets.DOMAIN_DOMAIN }}
|
||||
DOMAIN_HOST_IP: ${{ secrets.DOMAIN_HOST_IP }}
|
||||
uses: borales/actions-yarn@v2.0.0
|
||||
with:
|
||||
cmd: publish-records
|
||||
run: bun run publish-records
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
node_modules/
|
||||
*.env.*
|
||||
*.env.production
|
||||
*.log
|
||||
is-a-dev-cert/
|
||||
|
||||
+1
-2
@@ -3,11 +3,10 @@ let
|
||||
inherit (nixpkgs) pkgs;
|
||||
|
||||
nixPackages = with pkgs; [
|
||||
nodejs-18_x
|
||||
yarn
|
||||
docker-compose
|
||||
dnsutils
|
||||
#certbot
|
||||
bun
|
||||
];
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"description": "NotArya",
|
||||
"repo": "https://github.com/not-arya/not-arya.github.io",
|
||||
"owner": {
|
||||
"username": "not-arya",
|
||||
"email": "abiix.messanger@gmail.com"
|
||||
},
|
||||
"record": {
|
||||
"CNAME": "not-arya.github.io"
|
||||
}
|
||||
}
|
||||
+3
-11
@@ -3,27 +3,19 @@
|
||||
"version": "1.0.0",
|
||||
"description": "Register *.is-a.dev domains for free",
|
||||
"scripts": {
|
||||
"test": "ENV=test jest",
|
||||
"lint": "eslint utils scripts domains --ext .json,.js",
|
||||
"publish-records": "node ./scripts/register-domains.js",
|
||||
"publish-records": "bun run -b ./scripts/register-domains.js",
|
||||
"dc": "docker-compose -p is-a-dev",
|
||||
"dc:start": "yarn dc up",
|
||||
"dc:shell": "yarn dc run dev /bin/bash"
|
||||
"dc:start": "bun run dc up",
|
||||
"dc:shell": "bun run dc run dev /bin/bash"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/is-a-dev/register"
|
||||
},
|
||||
"keywords": [
|
||||
"subdomain"
|
||||
],
|
||||
"author": "Akshay Nair <phenax5@gmail.com>",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"dotenv": "^8.2.0",
|
||||
"jest": "^26.4.2",
|
||||
"node-fetch": "^2.6.1",
|
||||
"qs": "^6.9.4",
|
||||
"ramda": "^0.27.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -204,18 +204,18 @@ describe('Domain service', () => {
|
||||
{ name: 'c', type: 'MX', address: 'foobar.com', priority: 2 },
|
||||
]);
|
||||
|
||||
expect(addZone).toBeCalledTimes(1);
|
||||
expect(addZone).toHaveBeenCalledTimes(1);
|
||||
expect(getRecordCalls(addZone)).toEqual([
|
||||
{ name: 'c', type: 'A', address: '12.131321.213' },
|
||||
]);
|
||||
|
||||
expect(addEmail).toBeCalledTimes(1);
|
||||
expect(addEmail).toHaveBeenCalledTimes(1);
|
||||
expect(getRecordCalls(addEmail)).toEqual([
|
||||
{ domain: 'c.is-a.dev', exchanger: 'foobar.com', priority: 2 },
|
||||
]);
|
||||
|
||||
expect(removeZone).toBeCalledTimes(0);
|
||||
expect(removeEmail).toBeCalledTimes(0);
|
||||
expect(removeZone).toHaveBeenCalledTimes(0);
|
||||
expect(removeEmail).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('should update matching host and set it', async () => {
|
||||
@@ -231,11 +231,11 @@ describe('Domain service', () => {
|
||||
{ name: 'b', type: 'CNAME', address: 'googoogaga' },
|
||||
]);
|
||||
|
||||
expect(addZone).toBeCalledTimes(1);
|
||||
expect(addZone).toHaveBeenCalledTimes(1);
|
||||
expect(getRecordCalls(addZone)).toEqual([
|
||||
{ name: 'b', type: 'CNAME', address: 'googoogaga' },
|
||||
]);
|
||||
expect(removeZone).toBeCalledTimes(1);
|
||||
expect(removeZone).toHaveBeenCalledTimes(1);
|
||||
expect(getRecordCalls(removeZone)).toEqual([
|
||||
{ line: 2 },
|
||||
]);
|
||||
@@ -256,12 +256,12 @@ describe('Domain service', () => {
|
||||
{ name: 'b', type: 'CNAME', address: 'farboo' },
|
||||
]);
|
||||
|
||||
expect(addZone).toBeCalledTimes(2);
|
||||
expect(addZone).toHaveBeenCalledTimes(2);
|
||||
expect(getRecordCalls(addZone)).toEqual([
|
||||
{ name: 'b', type: 'CNAME', address: 'googoogaga' },
|
||||
{ name: 'b', type: 'CNAME', address: 'farboo' },
|
||||
]);
|
||||
expect(removeZone).toBeCalledTimes(2);
|
||||
expect(removeZone).toHaveBeenCalledTimes(2);
|
||||
expect(getRecordCalls(removeZone)).toEqual([
|
||||
{ line: 2 },
|
||||
{ line: 3 },
|
||||
@@ -300,34 +300,34 @@ describe('Domain service', () => {
|
||||
{ name: 'a', type: 'MX', address: 'example.com', priority: 20 },
|
||||
]);
|
||||
|
||||
expect(addZone).toBeCalledTimes(3);
|
||||
expect(addZone).toHaveBeenCalledTimes(3);
|
||||
expect(getRecordCalls(addZone)).toEqual([
|
||||
{ name: 'a', type: 'CNAME', address: 'boo' },
|
||||
{ name: 'b', type: 'A', address: '3' },
|
||||
{ name: 'd', type: 'CNAME', address: 'helo.com' },
|
||||
]);
|
||||
expect(removeZone).toBeCalledTimes(1);
|
||||
expect(removeZone).toHaveBeenCalledTimes(1);
|
||||
expect(getRecordCalls(removeZone)).toEqual([
|
||||
{ line: 1 },
|
||||
]);
|
||||
|
||||
expect(addEmail).toBeCalledTimes(1);
|
||||
expect(addEmail).toHaveBeenCalledTimes(1);
|
||||
expect(getRecordCalls(addEmail)).toEqual([
|
||||
{ domain: 'a.is-a.dev', exchanger: 'example.com', priority: 20 },
|
||||
]);
|
||||
expect(removeEmail).toBeCalledTimes(2);
|
||||
expect(removeEmail).toHaveBeenCalledTimes(2);
|
||||
expect(getRecordCalls(removeEmail)).toEqual([
|
||||
{ domain: 'c.is-a.dev', exchanger: 'mx1.hello.com', priority: 20 },
|
||||
{ domain: 'b.is-a.dev', exchanger: 'foo.bar', priority: 20 },
|
||||
]);
|
||||
|
||||
expect(addRedir).toBeCalledTimes(3);
|
||||
expect(addRedir).toHaveBeenCalledTimes(3);
|
||||
expect(getRecordCalls(addRedir)).toEqual([
|
||||
{ domain: `b.${DOMAIN_DOMAIN}`, type: 'permanent', redirect: 'https://wowow.com' },
|
||||
{ domain: `d.${DOMAIN_DOMAIN}`, type: 'permanent', redirect: 'https://hhh.com' },
|
||||
{ domain: `x.${DOMAIN_DOMAIN}`, type: 'permanent', redirect: 'https://example69.com' },
|
||||
]);
|
||||
expect(removeRedir).toBeCalledTimes(2);
|
||||
expect(removeRedir).toHaveBeenCalledTimes(2);
|
||||
expect(getRecordCalls(removeRedir)).toEqual([
|
||||
{ domain: `b.${DOMAIN_DOMAIN}` },
|
||||
{ domain: `x.${DOMAIN_DOMAIN}` },
|
||||
|
||||
+132
-75
@@ -1,7 +1,7 @@
|
||||
const R = require('ramda');
|
||||
const { toHostList, registerDomains } = require('../scripts/register-domains');
|
||||
const { TTL, DOMAIN_DOMAIN } = require('../utils/constants');
|
||||
const { getDomainService } = require('../utils/domain-service');
|
||||
const R = require('ramda')
|
||||
const { toHostList, registerDomains } = require('../scripts/register-domains')
|
||||
const { TTL, DOMAIN_DOMAIN } = require('../utils/constants')
|
||||
const { getDomainService } = require('../utils/domain-service')
|
||||
|
||||
const getCpanel = ({
|
||||
zone,
|
||||
@@ -11,7 +11,7 @@ const getCpanel = ({
|
||||
addRedir,
|
||||
removeRedir,
|
||||
addEmail,
|
||||
removeEmail
|
||||
removeEmail,
|
||||
} = {}) => ({
|
||||
zone: {
|
||||
fetch: (_) => zone(),
|
||||
@@ -27,7 +27,7 @@ const getCpanel = ({
|
||||
add: (rec) => addEmail(rec),
|
||||
remove: (rec) => removeEmail(rec),
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
describe('toHostList', () => {
|
||||
it('should flatten domain data to list of hosts (without https)', () => {
|
||||
@@ -36,7 +36,7 @@ describe('toHostList', () => {
|
||||
{ name: 'foobar', record: { CNAME: 'v.io' } },
|
||||
{ name: 'xx', record: { A: ['1.2.3.4', '5.6.3.2', '1.2.31.1'] } },
|
||||
{ name: 'xx', record: { CNAME: 'foobar.com', MX: ['as.com', 'f.com'] } },
|
||||
]);
|
||||
])
|
||||
|
||||
expect(res).toEqual([
|
||||
{ name: 'akshay', type: 'CNAME', address: 'phenax.github.io', ttl: TTL },
|
||||
@@ -47,106 +47,163 @@ describe('toHostList', () => {
|
||||
{ name: 'xx', type: 'CNAME', address: 'foobar.com', ttl: TTL },
|
||||
{ name: 'xx', type: 'MX', address: 'as.com', priority: 20, ttl: TTL },
|
||||
{ name: 'xx', type: 'MX', address: 'f.com', priority: 21, ttl: TTL },
|
||||
]);
|
||||
});
|
||||
});
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('registerDomains', () => {
|
||||
const addZone = jest.fn(async () => ({}));
|
||||
const removeZone = jest.fn(async () => ({}));
|
||||
const addRedir = jest.fn(async () => ({}));
|
||||
const removeRedir = jest.fn(async () => ({}));
|
||||
const addEmail = jest.fn(async () => ({}));
|
||||
const removeEmail = jest.fn(async () => ({}));
|
||||
const addZone = jest.fn(async () => ({}))
|
||||
const removeZone = jest.fn(async () => ({}))
|
||||
const addRedir = jest.fn(async () => ({}))
|
||||
const removeRedir = jest.fn(async () => ({}))
|
||||
const addEmail = jest.fn(async () => ({}))
|
||||
const removeEmail = jest.fn(async () => ({}))
|
||||
|
||||
const mockDS = ({ zones, redirections }) => getDomainService({
|
||||
cpanel: getCpanel({
|
||||
zone: async () => zones,
|
||||
redir: async () => redirections,
|
||||
addZone,
|
||||
addEmail,
|
||||
addRedir,
|
||||
removeZone,
|
||||
removeRedir,
|
||||
removeEmail,
|
||||
const mockDS = ({ zones, redirections }) =>
|
||||
getDomainService({
|
||||
cpanel: getCpanel({
|
||||
zone: async () => zones,
|
||||
redir: async () => redirections,
|
||||
addZone,
|
||||
addEmail,
|
||||
addRedir,
|
||||
removeZone,
|
||||
removeRedir,
|
||||
removeEmail,
|
||||
}),
|
||||
})
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
addZone.mockClear();
|
||||
removeZone.mockClear();
|
||||
addRedir.mockClear();
|
||||
removeRedir.mockClear();
|
||||
addEmail.mockClear();
|
||||
removeEmail.mockClear();
|
||||
});
|
||||
addZone.mockClear()
|
||||
removeZone.mockClear()
|
||||
addRedir.mockClear()
|
||||
removeRedir.mockClear()
|
||||
addEmail.mockClear()
|
||||
removeEmail.mockClear()
|
||||
})
|
||||
|
||||
it('should register the new set of hosts generated from domains list', async () => {
|
||||
const localHosts = [
|
||||
{ name: 'a', record: { CNAME: 'hello' } },
|
||||
{ name: 'b', record: { CNAME: 'xaa' } },
|
||||
];
|
||||
]
|
||||
const remoteHosts = [
|
||||
{ line: 1, name: 'a', type: 'CNAME', address: 'hello' },
|
||||
{ line: 2, name: 'b', type: 'CNAME', address: 'goo' },
|
||||
{ line: 3, name: 'b', type: 'CNAME', address: 'xaa' },
|
||||
];
|
||||
const remoteRedirections = [];
|
||||
]
|
||||
const remoteRedirections = []
|
||||
|
||||
const domainService = mockDS({ zones: remoteHosts, redirections: remoteRedirections });
|
||||
await registerDomains({ getDomains: async () => localHosts, domainService });
|
||||
const domainService = mockDS({
|
||||
zones: remoteHosts,
|
||||
redirections: remoteRedirections,
|
||||
})
|
||||
await registerDomains({ getDomains: async () => localHosts, domainService })
|
||||
|
||||
expect(addZone).toBeCalledTimes(0);
|
||||
expect(removeZone).toBeCalledTimes(1);
|
||||
expect(addRedir).toBeCalledTimes(0);
|
||||
expect(removeRedir).toBeCalledTimes(0);
|
||||
});
|
||||
expect(addZone).toHaveBeenCalledTimes(0)
|
||||
expect(removeZone).toHaveBeenCalledTimes(1)
|
||||
expect(addRedir).toHaveBeenCalledTimes(0)
|
||||
expect(removeRedir).toHaveBeenCalledTimes(0)
|
||||
})
|
||||
|
||||
it('should add the new set hosts', async () => {
|
||||
const localHosts = [
|
||||
{ name: 'a', record: { CNAME: 'boo' } },
|
||||
{ name: 'b', record: { A: [ '1.1.1.1', '1.1.1.2' ], MX: 'somemx', TXT: 'some txt' } },
|
||||
{
|
||||
name: 'b',
|
||||
record: { A: ['1.1.1.1', '1.1.1.2'], MX: 'somemx', TXT: 'some txt' },
|
||||
},
|
||||
{ name: 'c', record: { URL: 'https://google.com' } },
|
||||
{ name: 'd', record: { CNAME: 'foobar' } },
|
||||
{ name: 'e', record: { A: [ '2.2.2.2' ], TXT: ['some', 'extra', 'txt'] } }
|
||||
];
|
||||
{ name: 'e', record: { A: ['2.2.2.2'], TXT: ['some', 'extra', 'txt'] } },
|
||||
]
|
||||
const remoteHosts = [
|
||||
{ line: 1, name: 'a', type: 'CNAME', address: 'boo' },
|
||||
{ line: 2, name: 'b', type: 'MX', address: 'othermx' },
|
||||
{ line: 3, name: 'd', type: 'CNAME', address: 'foobaz' },
|
||||
];
|
||||
]
|
||||
const remoteRedirections = [
|
||||
{ domain: `b.${DOMAIN_DOMAIN}`, destination: 'x' },
|
||||
{ domain: `a.${DOMAIN_DOMAIN}`, destination: 'y' },
|
||||
];
|
||||
]
|
||||
|
||||
const domainService = mockDS({ zones: remoteHosts, redirections: remoteRedirections });
|
||||
await registerDomains({ getDomains: async () => localHosts, domainService });
|
||||
const domainService = mockDS({
|
||||
zones: remoteHosts,
|
||||
redirections: remoteRedirections,
|
||||
})
|
||||
await registerDomains({ getDomains: async () => localHosts, domainService })
|
||||
|
||||
expect(addZone).toBeCalledTimes(8);
|
||||
expect(addZone).toHaveBeenCalledWith({ name: 'b', type: 'A', address: '1.1.1.2', line: undefined });
|
||||
expect(addZone).toHaveBeenCalledWith({ name: 'd', type: 'CNAME', cname: 'foobar', address: 'foobar', line: undefined });
|
||||
expect(addZone).toHaveBeenCalledWith({ name: 'b', type: 'A', address: '1.1.1.2', line: undefined });
|
||||
expect(addZone).toHaveBeenCalledWith({ name: 'b', type: 'TXT', address: 'some txt', txtdata: 'some txt', line: undefined });
|
||||
expect(addZone).toHaveBeenCalledWith({ name: 'e', type: 'A', address: '2.2.2.2', line: undefined });
|
||||
expect(addZone).toHaveBeenCalledWith({ name: 'e', type: 'TXT', address: 'some', txtdata: 'some', line: undefined });
|
||||
expect(addZone).toHaveBeenCalledWith({ name: 'e', type: 'TXT', address: 'extra', txtdata: 'extra', line: undefined });
|
||||
expect(addZone).toHaveBeenCalledWith({ name: 'e', type: 'TXT', address: 'txt', txtdata: 'txt', line: undefined });
|
||||
expect(addZone).toHaveBeenCalledTimes(8)
|
||||
expect(addZone.mock.calls).toEqual([
|
||||
[{ name: 'b', type: 'A', address: '1.1.1.1', line: undefined }],
|
||||
[{ name: 'b', type: 'A', address: '1.1.1.2', line: undefined }],
|
||||
[
|
||||
{
|
||||
name: 'b',
|
||||
type: 'TXT',
|
||||
address: 'some txt',
|
||||
txtdata: 'some txt',
|
||||
line: undefined,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
name: 'd',
|
||||
type: 'CNAME',
|
||||
cname: 'foobar',
|
||||
address: 'foobar',
|
||||
line: undefined,
|
||||
},
|
||||
],
|
||||
[{ name: 'e', type: 'A', address: '2.2.2.2', line: undefined }],
|
||||
[
|
||||
{
|
||||
name: 'e',
|
||||
type: 'TXT',
|
||||
address: 'some',
|
||||
txtdata: 'some',
|
||||
line: undefined,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
name: 'e',
|
||||
type: 'TXT',
|
||||
address: 'extra',
|
||||
txtdata: 'extra',
|
||||
line: undefined,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
name: 'e',
|
||||
type: 'TXT',
|
||||
address: 'txt',
|
||||
txtdata: 'txt',
|
||||
line: undefined,
|
||||
},
|
||||
],
|
||||
])
|
||||
|
||||
expect(removeZone).toBeCalledTimes(1);
|
||||
expect(removeZone).toHaveBeenCalledWith({ line: 3 });
|
||||
expect(removeZone).toHaveBeenCalledTimes(1)
|
||||
expect(removeZone.mock.calls).toEqual([[{ line: 3 }]])
|
||||
|
||||
expect(addRedir).toBeCalledTimes(1);
|
||||
expect(addRedir).toHaveBeenCalledWith({
|
||||
domain: 'c.booboo.xyz',
|
||||
redirect: 'https://google.com',
|
||||
redirect_wildcard: 1,
|
||||
redirect_www: 1,
|
||||
type: 'permanent',
|
||||
});
|
||||
|
||||
expect(addEmail).toBeCalledTimes(1);
|
||||
expect(addEmail).toHaveBeenCalledWith({ domain: 'b.is-a.dev', exchanger: 'somemx', priority: 20 });
|
||||
});
|
||||
});
|
||||
expect(addRedir).toHaveBeenCalledTimes(1)
|
||||
expect(addRedir.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
domain: 'c.booboo.xyz',
|
||||
redirect: 'https://google.com',
|
||||
redirect_wildcard: 1,
|
||||
redirect_www: 1,
|
||||
type: 'permanent',
|
||||
},
|
||||
],
|
||||
])
|
||||
|
||||
expect(addEmail).toHaveBeenCalledTimes(1)
|
||||
expect(addEmail.mock.calls).toEqual([
|
||||
[{ domain: 'b.is-a.dev', exchanger: 'somemx', priority: 20 }],
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
+1
-5
@@ -1,10 +1,6 @@
|
||||
const path = require('path');
|
||||
|
||||
const { ENV = 'test', CI } = process.env;
|
||||
|
||||
if (!CI) {
|
||||
require('dotenv').config({ path: path.resolve(`.env.${ENV}`) });
|
||||
}
|
||||
const { NODE_ENV: ENV = 'test' } = process.env;
|
||||
|
||||
const {
|
||||
DOMAIN_USER,
|
||||
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
const R = require('ramda');
|
||||
const fetch = require('node-fetch');
|
||||
const qs = require('qs');
|
||||
const qs = require('querystring');
|
||||
const { DOMAIN_API_HOST, DOMAIN_API_PORT, DOMAIN_USER, DOMAIN_API_KEY, DOMAIN_DOMAIN } = require('../constants');
|
||||
|
||||
const CpanelClient = (options) => {
|
||||
|
||||
Reference in New Issue
Block a user