File tree Expand file tree Collapse file tree 3 files changed +58
-2
lines changed Expand file tree Collapse file tree 3 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { marshall } from "@aws-sdk/util-dynamodb";
77import { genericConfig } from "common/config.js" ;
88import { FastifyBaseLogger } from "fastify" ;
99import { isUserInGroup } from "./entraId.js" ;
10+ import { EntraGroupError } from "common/errors/index.js" ;
1011
1112export async function checkPaidMembership (
1213 endpoint : string ,
@@ -58,7 +59,14 @@ export async function checkPaidMembershipFromEntra(
5859 entraToken : string ,
5960 paidMemberGroup : string ,
6061) : Promise < boolean > {
61- return isUserInGroup ( entraToken , `${ netId } @illinois.edu` , paidMemberGroup ) ;
62+ try {
63+ return isUserInGroup ( entraToken , `${ netId } @illinois.edu` , paidMemberGroup ) ;
64+ } catch ( e ) {
65+ if ( e instanceof EntraGroupError ) {
66+ return false ;
67+ }
68+ throw e ;
69+ }
6270}
6371
6472export async function setPaidMembershipInTable (
Original file line number Diff line number Diff line change @@ -8,5 +8,5 @@ export function validateEmail(email: string): boolean {
88
99export function validateNetId ( netId : string ) : boolean {
1010 const regex = / ^ [ a - z A - Z ] { 2 } [ a - z A - Z \- ] * (?: [ 2 - 9 ] | [ 1 - 9 ] [ 0 - 9 ] { 1 , 2 } ) ? $ / ;
11- return regex . test ( netId ) ;
11+ return netId . length <= 8 && regex . test ( netId ) ;
1212}
Original file line number Diff line number Diff line change 1+ import { expect , test , describe } from "vitest" ;
2+
3+ const baseEndpoint = `https://core.aws.qa.acmuiuc.org` ;
4+
5+ describe ( "Membership API basic checks" , async ( ) => {
6+ test ( "Test that getting member succeeds" , { timeout : 3000 } , async ( ) => {
7+ const response = await fetch ( `${ baseEndpoint } /api/v1/membership/dsingh14` , {
8+ method : "GET" ,
9+ } ) ;
10+
11+ expect ( response . status ) . toBe ( 200 ) ;
12+
13+ const responseBody = await response . json ( ) ;
14+ expect ( responseBody ) . toStrictEqual ( {
15+ netId : "dsingh14" ,
16+ isPaidMember : true ,
17+ } ) ;
18+ expect ( response . headers . get ( "x-acm-data-source" ) ) . toBe ( "dynamo" ) ;
19+ } ) ;
20+ test (
21+ "Test that getting non-members succeeds" ,
22+ { timeout : 3000 } ,
23+ async ( ) => {
24+ const response = await fetch ( `${ baseEndpoint } /api/v1/membership/zzzz` , {
25+ method : "GET" ,
26+ } ) ;
27+
28+ expect ( response . status ) . toBe ( 200 ) ;
29+
30+ const responseBody = await response . json ( ) ;
31+ expect ( responseBody ) . toStrictEqual ( {
32+ netId : "zzzz" ,
33+ isPaidMember : false ,
34+ } ) ;
35+ expect ( response . headers . get ( "x-acm-data-source" ) ) . toBe ( "aad" ) ;
36+ } ,
37+ ) ;
38+ test ( "Test that invalid NetID is rejected" , { timeout : 3000 } , async ( ) => {
39+ const response = await fetch (
40+ `${ baseEndpoint } /api/v1/membership/dsafdsfdsfsdafsfsdfasfsfsfds` ,
41+ {
42+ method : "GET" ,
43+ } ,
44+ ) ;
45+
46+ expect ( response . status ) . toBe ( 400 ) ;
47+ } ) ;
48+ } ) ;
You can’t perform that action at this time.
0 commit comments