mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Add node-radius definitions and tests
More info about node library: https://github.com/retailnext/node-radius
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/// <reference path="radius.d.ts" />
|
||||
|
||||
import radius = require('radius');
|
||||
|
||||
var radius_secret: string = "shhhh"
|
||||
|
||||
radius.add_dictionary("./");
|
||||
var encodedPacket: NodeBuffer = radius.encode({
|
||||
code: "Access-Request",
|
||||
secret: radius_secret,
|
||||
attributes: {
|
||||
"NAS-IP-Address": "10.5.5.5",
|
||||
"User-Name": "me",
|
||||
"User-Password": "its-a-secret"
|
||||
}
|
||||
});
|
||||
|
||||
var radiusPacket: radius.RadiusPacket = radius.decode({
|
||||
packet: encodedPacket,
|
||||
secret: radius_secret
|
||||
});
|
||||
|
||||
var response: NodeBuffer;
|
||||
|
||||
if (radiusPacket.attributes["User-Name"] == "me" && radiusPacket.attributes["User-Password"] == "its-a-secret") {
|
||||
response = radius.encode_response({
|
||||
packet: radiusPacket,
|
||||
code: "Access-Accept",
|
||||
secret: radius_secret
|
||||
});
|
||||
} else {
|
||||
response = radius.encode_response({
|
||||
packet: radiusPacket,
|
||||
code: "Access-Reject",
|
||||
secret: radius_secret
|
||||
});
|
||||
}
|
||||
|
||||
console.log(radius.verify_response({
|
||||
request: encodedPacket,
|
||||
response: response,
|
||||
secret: radius_secret
|
||||
}));
|
||||
Vendored
+106
@@ -0,0 +1,106 @@
|
||||
// Type definitions for node-radius
|
||||
// Project: https://github.com/retailnext/node-radius
|
||||
// Definitions by: Peter Harris <https://github.com/codeanimal>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
interface NodeBuffer { }
|
||||
|
||||
declare module "radius" {
|
||||
/**
|
||||
* {@link https://github.com/retailnext/node-radius#radiusdecodeargs} for more info.
|
||||
**/
|
||||
export function decode(args: DecodeArgsWithSecret): RadiusPacket;
|
||||
|
||||
/**
|
||||
* {@link https://github.com/retailnext/node-radius#radiusdecode_without_secretargs} for more info.
|
||||
**/
|
||||
export function decode_without_secret(args: DecodeArgs): RadiusPacket;
|
||||
|
||||
/**
|
||||
* {@link https://github.com/retailnext/node-radius#radiusencodeargs} for more info.
|
||||
**/
|
||||
export function encode(args: EncodeArgs): NodeBuffer;
|
||||
|
||||
/**
|
||||
* {@link https://github.com/retailnext/node-radius#radiusencode_responseargs} for more info.
|
||||
**/
|
||||
export function encode_response(args: EncodeResponseArgs): NodeBuffer;
|
||||
|
||||
/**
|
||||
* {@link https://github.com/retailnext/node-radius#radiusverify_responseargs} for more info.
|
||||
**/
|
||||
export function verify_response(args: VerifyResponseArgs):boolean;
|
||||
|
||||
/**
|
||||
* {@link https://github.com/retailnext/node-radius#radiusadd_dictionarypath} for more info.
|
||||
*
|
||||
* @param path Can be either a path to a file or a directory.
|
||||
**/
|
||||
export function add_dictionary(path:string);
|
||||
|
||||
export function unload_dictionaries();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* {@link https://github.com/retailnext/node-radius#radiusdecode_without_secretargs} for more info.
|
||||
**/
|
||||
interface DecodeArgs {
|
||||
packet: NodeBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link https://github.com/retailnext/node-radius#radiusdecodeargs} for more info.
|
||||
**/
|
||||
interface DecodeArgsWithSecret extends DecodeArgs {
|
||||
secret: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link https://github.com/retailnext/node-radius#radiusencodeargs} for more info.
|
||||
**/
|
||||
interface EncodeArgs {
|
||||
code: string;
|
||||
secret: string;
|
||||
identifier?: number;
|
||||
/**
|
||||
* This can be an object: { attribute_name: attribute_value, ... },
|
||||
* an array within an array: [ [ attribute_name, attribute_value ], ... ],
|
||||
* or if you haven't loaded a dictionary for the attributes: [ [ attribute_id, Buffer ], ... ].
|
||||
*
|
||||
* Tag field-attributes can be specified like so: [ [ attribute_name, tag_number, attribute_value ] ... ]
|
||||
**/
|
||||
attributes?: any;
|
||||
add_message_authenticator?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link https://github.com/retailnext/node-radius#radiusencode_responseargs} for more info.
|
||||
**/
|
||||
interface EncodeResponseArgs {
|
||||
packet: RadiusPacket;
|
||||
code: string;
|
||||
secret: string;
|
||||
attributes?: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link https://github.com/retailnext/node-radius#radiusverify_responseargs} for more info.
|
||||
**/
|
||||
interface VerifyResponseArgs {
|
||||
request: NodeBuffer;
|
||||
response: NodeBuffer;
|
||||
secret: string;
|
||||
}
|
||||
|
||||
interface RadiusPacket {
|
||||
code: string;
|
||||
identifier: number;
|
||||
length: number;
|
||||
attributes: any;
|
||||
raw_attributes: Array<Array<any>>
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user