fix(detector): Improve test coverage and adjust detection result handling
This commit is contained in:
@@ -29,9 +29,13 @@ export class Detector {
|
||||
isActive: portAvailable
|
||||
};
|
||||
|
||||
if (portAvailable && options?.detectServiceType) {
|
||||
const serviceType = await this.detectType(urlArg);
|
||||
result.serviceType = serviceType;
|
||||
if (options?.detectServiceType) {
|
||||
if (portAvailable) {
|
||||
const serviceType = await this.detectType(urlArg);
|
||||
result.serviceType = serviceType;
|
||||
} else {
|
||||
result.serviceType = ServiceType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -46,9 +50,13 @@ export class Detector {
|
||||
isActive: portAvailable
|
||||
};
|
||||
|
||||
if (portAvailable && options?.detectServiceType) {
|
||||
const serviceType = await this.detectType(urlArg);
|
||||
result.serviceType = serviceType;
|
||||
if (options?.detectServiceType) {
|
||||
if (portAvailable) {
|
||||
const serviceType = await this.detectType(urlArg);
|
||||
result.serviceType = serviceType;
|
||||
} else {
|
||||
result.serviceType = ServiceType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -57,7 +65,27 @@ export class Detector {
|
||||
|
||||
public async detectType(urlArg: string): Promise<ServiceType> {
|
||||
const parsedUrl = plugins.smarturl.Smarturl.createFromUrl(urlArg);
|
||||
const port = parseInt(parsedUrl.port, 10);
|
||||
|
||||
// Handle different URL schemes and default ports
|
||||
let port = parseInt(parsedUrl.port, 10);
|
||||
if (isNaN(port)) {
|
||||
// Set default ports based on scheme
|
||||
const defaultPorts: { [key: string]: number } = {
|
||||
'http': 80,
|
||||
'https': 443,
|
||||
'ssh': 22,
|
||||
'ftp': 21,
|
||||
'smtp': 25,
|
||||
'mysql': 3306,
|
||||
'postgresql': 5432,
|
||||
'mongodb': 27017,
|
||||
'redis': 6379
|
||||
};
|
||||
|
||||
const scheme = parsedUrl.protocol.replace(':', '').toLowerCase();
|
||||
port = defaultPorts[scheme] || 80;
|
||||
}
|
||||
|
||||
const hostname = parsedUrl.hostname;
|
||||
|
||||
// Check common ports first
|
||||
|
||||
Reference in New Issue
Block a user