File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 1+ import { describe , expect , test } from "vitest" ;
2+ import { getBaseEndpoint , makeRandomString } from "./utils.js" ;
3+
4+ const baseEndpoint = getBaseEndpoint ( "go" ) ;
5+
6+ describe ( "Linkry live tests" , async ( ) => {
7+ test ( "Linkry health check" , async ( ) => {
8+ const response = await fetch ( `${ baseEndpoint } /healthz` ) ;
9+ expect ( response . status ) . toBe ( 200 ) ;
10+ expect ( response . redirected ) . toBe ( true ) ;
11+ expect ( response . url ) . toBe ( "https://www.google.com/" ) ;
12+ } ) ;
13+ test ( "Linkry 404 redirect" , async ( ) => {
14+ const response = await fetch ( `${ baseEndpoint } /${ makeRandomString ( 16 ) } ` ) ;
15+ expect ( response . status ) . toBe ( 200 ) ;
16+ expect ( response . redirected ) . toBe ( true ) ;
17+ expect ( response . url ) . toBe ( "https://www.acm.illinois.edu/404" ) ;
18+ } ) ;
19+ } ) ;
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ async function getSecrets() {
3333 keyData = await getSecretValue ( "infra-core-api-config" ) ;
3434 }
3535 response [ "JWTKEY" ] =
36- process . env . JWT_KEY || ( keyData ? keyData [ "jwt_key" ] : "" ) ;
36+ process . env . JWT_KEY || ( ( keyData ? keyData [ "jwt_key" ] : "" ) as string ) ;
3737 return response ;
3838}
3939
@@ -70,3 +70,29 @@ export async function createJwt(
7070 const token = jwt . sign ( payload , secretData . JWTKEY , { algorithm : "HS256" } ) ;
7171 return token ;
7272}
73+
74+ type Service = "core" | "go" | "ical" ;
75+
76+ export function getBaseEndpoint ( service ?: Service ) {
77+ const base = process . env . CORE_BASE_URL ?? "https://core.aws.qa.acmuiuc.org" ;
78+ if (
79+ base . includes ( "localhost" ) ||
80+ base . includes ( "127.0.0.1" ) ||
81+ base . includes ( "::1" ) ||
82+ ! service
83+ ) {
84+ return base ;
85+ }
86+ return base . replace ( "core" , service ) ;
87+ }
88+
89+ export function makeRandomString ( length : number ) {
90+ var result = "" ;
91+ var characters =
92+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ;
93+ var charactersLength = characters . length ;
94+ for ( var i = 0 ; i < length ; i ++ ) {
95+ result += characters . charAt ( Math . floor ( Math . random ( ) * charactersLength ) ) ;
96+ }
97+ return result ;
98+ }
You can’t perform that action at this time.
0 commit comments