Skip to content

Commit

Permalink
add more validation for server
Browse files Browse the repository at this point in the history
currently many providers are failing
  • Loading branch information
WofWca authored and missytake committed Mar 25, 2024
1 parent 2aaef1c commit f63f503
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions validation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,34 @@ function testServer(server){

if(!server.hostname || server.hostname.trim() == "") throw new Error("Hostname missing")
if(!server.port) throw new Error("Port missing")
if(!server.socket || server.socket.trim() == "") throw new Error("Socket missing")
if(!server.type || server.type.trim() == "") throw new Error("Type missing")

// todo username_pattern optional but one of right the values
if(
!server.socket ||
server.socket.trim() == "" ||
!["SSL", "STARTTLS", "PLAIN"].includes(server.socket.trim())
) throw new Error(`Invalid Socket "${server.socket}"`)
if(
!server.type ||
server.type.trim() == "" ||
!["IMAP", "SMTP"].includes(server.type.trim().toUpperCase())
) throw new Error(`Invalid type "${server.type}"`)
if(
server.username_pattern &&
!["EMAIL", "EMAILLOCALPART"].includes(
server.username_pattern.trim().toUpperCase()
)
) throw new Error(`Invalid username_pattern "${server.username_pattern}"`)

for (const key of Object.keys(server)) {
if (![
"type",
"socket",
"hostname",
"port",
"username_pattern",
].includes(key)) {
throw new Error(`Unexpected key "${key}"`)
}
}
}

function test(fileContent) {
Expand Down

0 comments on commit f63f503

Please sign in to comment.