Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more validation for server #288

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading