@@ -5,9 +5,8 @@ import { getIdentifier } from '../config';
55const identifier = getIdentifier ( ) ;
66const stackName = `integ-${ identifier } -delegated-auth` ;
77
8- // Function names from CDK stack
9- const HAPPY_PATH_FUNCTION = `${ stackName } -happy-path` ;
10- const FALLBACK_FUNCTION = `${ stackName } -fallback` ;
8+ // Function name matches the CDK stack id
9+ const FUNCTION_NAME = stackName ;
1110
1211// Default wait time for Datadog to index logs and traces after Lambda invocation
1312const DEFAULT_DATADOG_INDEXING_WAIT_MS = 5 * 60 * 1000 ; // 5 minutes
@@ -33,146 +32,64 @@ async function getDatadogTelemetryByRequestId(
3332}
3433
3534describe ( 'Delegated Authentication Integration Tests' , ( ) => {
35+ let invocationResult : { requestId : string ; statusCode ?: number } ;
36+ let telemetry : DatadogTelemetry ;
37+ let logs : string [ ] ;
3638
37- describe ( 'Happy Path - Delegated Auth Success' , ( ) => {
38- let invocationResult : { requestId : string ; statusCode ?: number } ;
39- let telemetry : DatadogTelemetry ;
40- let logs : string [ ] ;
41-
42- beforeAll ( async ( ) => {
43- console . log ( `Testing happy path function: ${ HAPPY_PATH_FUNCTION } ` ) ;
44-
45- // Force cold start to ensure extension initializes fresh
46- await forceColdStart ( HAPPY_PATH_FUNCTION ) ;
47-
48- // Invoke the function
49- invocationResult = await invokeLambda ( HAPPY_PATH_FUNCTION , { } ) ;
50-
51- console . log ( `Invocation completed, requestId: ${ invocationResult . requestId } ` ) ;
52-
53- // Wait for telemetry to be indexed in Datadog
54- console . log ( `Waiting ${ DEFAULT_DATADOG_INDEXING_WAIT_MS / 1000 } s for Datadog indexing...` ) ;
55- await sleep ( DEFAULT_DATADOG_INDEXING_WAIT_MS ) ;
56-
57- // Collect telemetry from Datadog
58- telemetry = await getDatadogTelemetryByRequestId (
59- HAPPY_PATH_FUNCTION ,
60- invocationResult . requestId
61- ) ;
62- logs = telemetry . logs . map ( ( log : DatadogLog ) => log . message ) ;
63-
64- console . log ( `Collected ${ telemetry . logs . length } logs and ${ telemetry . traces . length } traces` ) ;
65- } , 600000 ) ; // 10 minute timeout
66-
67- it ( 'should invoke Lambda successfully' , ( ) => {
68- expect ( invocationResult ) . toBeDefined ( ) ;
69- expect ( invocationResult . statusCode ) . toBe ( 200 ) ;
70- } ) ;
71-
72- it ( 'should have function log output' , ( ) => {
73- expect ( telemetry ) . toBeDefined ( ) ;
74- expect ( telemetry . logs ) . toBeDefined ( ) ;
75- expect ( telemetry . logs . length ) . toBeGreaterThan ( 0 ) ;
76- } ) ;
77-
78- it ( 'should show delegated auth API key obtained successfully' , ( ) => {
79- // Look for log message indicating delegated auth succeeded
80- const delegatedAuthLog = logs . find ( ( log : string ) =>
81- log . includes ( 'Delegated auth' ) &&
82- ( log . includes ( 'API key obtained' ) || log . includes ( 'success' ) )
83- ) ;
84- expect ( delegatedAuthLog ) . toBeDefined ( ) ;
85- } ) ;
86-
87- it ( 'should NOT show fallback to static API key' , ( ) => {
88- // Ensure no fallback occurred
89- const fallbackLog = logs . find ( ( log : string ) =>
90- log . includes ( 'fallback' ) || log . includes ( 'Falling back' )
91- ) ;
92- expect ( fallbackLog ) . toBeUndefined ( ) ;
93- } ) ;
94-
95- it ( 'should send telemetry to Datadog (validates API key works)' , ( ) => {
96- // If we have logs in Datadog, the obtained API key is working
97- expect ( telemetry . logs ) . toBeDefined ( ) ;
98- expect ( telemetry . logs . length ) . toBeGreaterThan ( 0 ) ;
99- } ) ;
100-
101- it ( 'should send at least one trace to Datadog' , ( ) => {
102- // Traces indicate the extension is functioning correctly
103- expect ( telemetry . traces ) . toBeDefined ( ) ;
104- expect ( telemetry . traces . length ) . toBeGreaterThanOrEqual ( 1 ) ;
105- } ) ;
39+ beforeAll ( async ( ) => {
40+ console . log ( `Testing delegated auth function: ${ FUNCTION_NAME } ` ) ;
41+
42+ // Force cold start to ensure extension initializes fresh
43+ await forceColdStart ( FUNCTION_NAME ) ;
44+
45+ // Invoke the function
46+ invocationResult = await invokeLambda ( FUNCTION_NAME , { } ) ;
47+
48+ console . log ( `Invocation completed, requestId: ${ invocationResult . requestId } ` ) ;
49+
50+ // Wait for telemetry to be indexed in Datadog
51+ console . log ( `Waiting ${ DEFAULT_DATADOG_INDEXING_WAIT_MS / 1000 } s for Datadog indexing...` ) ;
52+ await sleep ( DEFAULT_DATADOG_INDEXING_WAIT_MS ) ;
53+
54+ // Collect telemetry from Datadog
55+ telemetry = await getDatadogTelemetryByRequestId (
56+ FUNCTION_NAME ,
57+ invocationResult . requestId
58+ ) ;
59+ logs = telemetry . logs . map ( ( log : DatadogLog ) => log . message ) ;
60+
61+ console . log ( `Collected ${ telemetry . logs . length } logs and ${ telemetry . traces . length } traces` ) ;
62+ } , 600000 ) ; // 10 minute timeout
63+
64+ it ( 'should invoke Lambda successfully' , ( ) => {
65+ expect ( invocationResult ) . toBeDefined ( ) ;
66+ expect ( invocationResult . statusCode ) . toBe ( 200 ) ;
10667 } ) ;
10768
108- describe ( 'Fallback Path - Invalid Org UUID Falls Back to Static Key' , ( ) => {
109- let invocationResult : { requestId : string ; statusCode ?: number } ;
110- let telemetry : DatadogTelemetry ;
111- let logs : string [ ] ;
112-
113- beforeAll ( async ( ) => {
114- console . log ( `Testing fallback function: ${ FALLBACK_FUNCTION } ` ) ;
115-
116- // Force cold start to ensure extension initializes fresh
117- await forceColdStart ( FALLBACK_FUNCTION ) ;
118-
119- // Invoke the function
120- invocationResult = await invokeLambda ( FALLBACK_FUNCTION , { } ) ;
121-
122- console . log ( `Invocation completed, requestId: ${ invocationResult . requestId } ` ) ;
123-
124- // Wait for telemetry to be indexed in Datadog
125- console . log ( `Waiting ${ DEFAULT_DATADOG_INDEXING_WAIT_MS / 1000 } s for Datadog indexing...` ) ;
126- await sleep ( DEFAULT_DATADOG_INDEXING_WAIT_MS ) ;
127-
128- // Collect telemetry from Datadog
129- telemetry = await getDatadogTelemetryByRequestId (
130- FALLBACK_FUNCTION ,
131- invocationResult . requestId
132- ) ;
133- logs = telemetry . logs . map ( ( log : DatadogLog ) => log . message ) ;
134-
135- console . log ( `Collected ${ telemetry . logs . length } logs and ${ telemetry . traces . length } traces` ) ;
136- } , 600000 ) ; // 10 minute timeout
137-
138- it ( 'should invoke Lambda successfully' , ( ) => {
139- expect ( invocationResult ) . toBeDefined ( ) ;
140- expect ( invocationResult . statusCode ) . toBe ( 200 ) ;
141- } ) ;
142-
143- it ( 'should have function log output' , ( ) => {
144- expect ( telemetry ) . toBeDefined ( ) ;
145- expect ( telemetry . logs ) . toBeDefined ( ) ;
146- expect ( telemetry . logs . length ) . toBeGreaterThan ( 0 ) ;
147- } ) ;
148-
149- it ( 'should show delegated auth failure' , ( ) => {
150- // Look for log message indicating delegated auth failed
151- const failureLog = logs . find ( ( log : string ) =>
152- ( log . includes ( 'Delegated auth' ) || log . includes ( 'delegated auth' ) ) &&
153- ( log . includes ( 'fail' ) || log . includes ( 'error' ) || log . includes ( 'Error' ) )
154- ) ;
155- expect ( failureLog ) . toBeDefined ( ) ;
156- } ) ;
157-
158- it ( 'should show fallback to static API key' , ( ) => {
159- // Look for log message indicating fallback occurred
160- const fallbackLog = logs . find ( ( log : string ) =>
161- log . includes ( 'fallback' ) || log . includes ( 'Falling back' ) || log . includes ( 'using static' )
162- ) ;
163- expect ( fallbackLog ) . toBeDefined ( ) ;
164- } ) ;
165-
166- it ( 'should still send telemetry to Datadog (via fallback key)' , ( ) => {
167- // Even with delegated auth failure, telemetry should work via fallback
168- expect ( telemetry . logs ) . toBeDefined ( ) ;
169- expect ( telemetry . logs . length ) . toBeGreaterThan ( 0 ) ;
170- } ) ;
171-
172- it ( 'should still send traces to Datadog (via fallback key)' , ( ) => {
173- // Traces should still work via the fallback static API key
174- expect ( telemetry . traces ) . toBeDefined ( ) ;
175- expect ( telemetry . traces . length ) . toBeGreaterThanOrEqual ( 1 ) ;
176- } ) ;
69+ it ( 'should have function log output' , ( ) => {
70+ expect ( telemetry ) . toBeDefined ( ) ;
71+ expect ( telemetry . logs ) . toBeDefined ( ) ;
72+ expect ( telemetry . logs . length ) . toBeGreaterThan ( 0 ) ;
17773 } ) ;
74+
75+ it ( 'should show delegated auth API key obtained successfully' , ( ) => {
76+ const delegatedAuthLog = logs . find ( ( log : string ) =>
77+ log . includes ( 'Delegated auth' ) &&
78+ ( log . includes ( 'API key obtained' ) || log . includes ( 'success' ) )
79+ ) ;
80+ expect ( delegatedAuthLog ) . toBeDefined ( ) ;
81+ } ) ;
82+
83+ it ( 'should NOT show fallback to static API key' , ( ) => {
84+ const fallbackLog = logs . find ( ( log : string ) =>
85+ log . includes ( 'fallback' ) || log . includes ( 'Falling back' )
86+ ) ;
87+ expect ( fallbackLog ) . toBeUndefined ( ) ;
88+ } ) ;
89+
90+ it ( 'should send telemetry to Datadog (validates API key works)' , ( ) => {
91+ expect ( telemetry . logs ) . toBeDefined ( ) ;
92+ expect ( telemetry . logs . length ) . toBeGreaterThan ( 0 ) ;
93+ } ) ;
94+
17895} ) ;
0 commit comments