mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-05-24 04:24:46 +00:00
Merge branch 'main' into main
This commit is contained in:
+2
-1
@@ -6,6 +6,7 @@
|
||||
"email": "phenax5@gmail.com"
|
||||
},
|
||||
"record": {
|
||||
"URL": "https://phenax.github.io"
|
||||
"URL": "https://phenax.github.io",
|
||||
"TXT": [ "Hello there!", "It's me, Akshay" ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"owner": {
|
||||
"username": "MrBogdanYT",
|
||||
"email": "hysbskyblockgod@gmail.com"
|
||||
},
|
||||
"record": {
|
||||
"A": ["217.174.245.249"],
|
||||
"MX": ["hosts.is-a.dev"],
|
||||
"TXT": "v=spf1 a mx ip4:217.174.245.249 ~all"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"owner": {
|
||||
"username": "DenDanskeMine",
|
||||
"email": "christianhrose@outlook.dk"
|
||||
},
|
||||
"record": {
|
||||
"A": ["217.174.245.249"],
|
||||
"MX": ["hosts.is-a.dev"],
|
||||
"TXT": "v=spf1 a mx ip4:217.174.245.249 ~all"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"owner": {
|
||||
"username": "NoahPrm",
|
||||
"email": "noah.parmentier@icloud.com"
|
||||
},
|
||||
|
||||
"record": {
|
||||
"A": ["185.143.241.106"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"owner": {
|
||||
"username": "npc-123",
|
||||
"email": "aziznasrul85@gmail.com"
|
||||
},
|
||||
"record": {
|
||||
"A": ["217.174.245.249"],
|
||||
"MX": ["hosts.is-a.dev"],
|
||||
"TXT": "v=spf1 a mx ip4:217.174.245.249 ~all"
|
||||
}
|
||||
}
|
||||
+41
-9
@@ -3,7 +3,16 @@ const { toHostList, registerDomains } = require('../scripts/register-domains');
|
||||
const { TTL, DOMAIN_DOMAIN } = require('../utils/constants');
|
||||
const { getDomainService } = require('../utils/domain-service');
|
||||
|
||||
const getCpanel = ({ zone, addZone, removeZone, redir, addRedir, removeRedir } = {}) => ({
|
||||
const getCpanel = ({
|
||||
zone,
|
||||
addZone,
|
||||
removeZone,
|
||||
redir,
|
||||
addRedir,
|
||||
removeRedir,
|
||||
addEmail,
|
||||
removeEmail
|
||||
} = {}) => ({
|
||||
zone: {
|
||||
fetch: (_) => zone(),
|
||||
add: (rec) => addZone(rec),
|
||||
@@ -95,13 +104,16 @@ describe('registerDomains', () => {
|
||||
|
||||
it('should add the new set hosts', async () => {
|
||||
const localHosts = [
|
||||
{ name: 'a', record: { CNAME: 'boo', URL: 'z' } },
|
||||
{ name: 'b', record: { CNAME: 'xaa', URL: 'x' } },
|
||||
{ name: 'c', record: { CNAME: 'yello', URL: 'https://google.com' } },
|
||||
{ name: 'a', record: { CNAME: 'boo' } },
|
||||
{ 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'] } }
|
||||
];
|
||||
const remoteHosts = [
|
||||
{ line: 1, name: 'a', type: 'CNAME', address: 'boo' },
|
||||
{ line: 2, name: 'b', type: 'CNAME', address: 'xaa' },
|
||||
{ line: 2, name: 'b', type: 'MX', address: 'othermx' },
|
||||
{ line: 3, name: 'd', type: 'CNAME', address: 'foobaz' },
|
||||
];
|
||||
const remoteRedirections = [
|
||||
{ domain: `b.${DOMAIN_DOMAIN}`, destination: 'x' },
|
||||
@@ -111,10 +123,30 @@ describe('registerDomains', () => {
|
||||
const domainService = mockDS({ zones: remoteHosts, redirections: remoteRedirections });
|
||||
await registerDomains({ getDomains: async () => localHosts, domainService });
|
||||
|
||||
expect(addZone).toBeCalledTimes(1);
|
||||
expect(removeZone).toBeCalledTimes(0);
|
||||
expect(addRedir).toBeCalledTimes(2);
|
||||
expect(removeRedir).toBeCalledTimes(1);
|
||||
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(removeZone).toBeCalledTimes(1);
|
||||
expect(removeZone).toHaveBeenCalledWith({ 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 });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ describe('validateDomainData', () => {
|
||||
{ ...defaultDomain, record: { CNAME: 'foobar.com', A: ['11.22.22.33'] } },
|
||||
{ ...defaultDomain, record: { CNAME: 'foobar.com', MX: ['ALT4.ASPMX.L.GOOGLE.COM'] } },
|
||||
...INVALID_NAMES.map(name => ({ ...defaultDomain, name })).slice(0, 1),
|
||||
{ ...defaultDomain, record: { TXT: ['foobar wow nice!!!'] } },
|
||||
{ ...defaultDomain, name: 'a.b' },
|
||||
{ ...defaultDomain, name: 'ww2.baa' },
|
||||
{ ...defaultDomain, name: 'help.baa' },
|
||||
@@ -86,6 +85,7 @@ describe('validateDomainData', () => {
|
||||
{ ...defaultDomain, name: '_github-challenge-phenax.akshay' },
|
||||
{ ...defaultDomain, name: '_github-challenge-hello01-ga' },
|
||||
{ ...defaultDomain, name: '_github-challenge-hello01_ga' },
|
||||
{ ...defaultDomain, record: { TXT: ['foobar wow nice!!!', 'more text'] } },
|
||||
];
|
||||
|
||||
it('should return false for invalid data', () => {
|
||||
|
||||
@@ -74,7 +74,7 @@ const validateDomainData = validate({
|
||||
[R.has('A'), validateARecord('A')],
|
||||
[R.has('URL'), R.propSatisfies(isValidURL, 'URL')],
|
||||
[R.has('MX'), validateMXRecord('MX')],
|
||||
[R.has('TXT'), R.propSatisfies(R.is(String), 'TXT')],
|
||||
[R.has('TXT'), R.propSatisfies(or([ R.is(String), R.is(Array) ]), 'TXT')],
|
||||
[R.T, R.T],
|
||||
]),
|
||||
]),
|
||||
|
||||
Reference in New Issue
Block a user