| 
						
						
						
					 | 
					 | 
					@ -1,3 +1,4 @@
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					import { type Server, serve } from "bun";
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import { describe, expect, it } from "bun:test";
 | 
					 | 
					 | 
					 | 
					import { describe, expect, it } from "bun:test";
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import {
 | 
					 | 
					 | 
					 | 
					import {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  createJSONResponse,
 | 
					 | 
					 | 
					 | 
					  createJSONResponse,
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -9,7 +10,6 @@ import {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  testRequiredVariables,
 | 
					 | 
					 | 
					 | 
					  testRequiredVariables,
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  writeCoder,
 | 
					 | 
					 | 
					 | 
					  writeCoder,
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					} from "../test";
 | 
					 | 
					 | 
					 | 
					} from "../test";
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import { Server, serve } from "bun";
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					describe("github-upload-public-key", async () => {
 | 
					 | 
					 | 
					 | 
					describe("github-upload-public-key", async () => {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  await runTerraformInit(import.meta.dir);
 | 
					 | 
					 | 
					 | 
					  await runTerraformInit(import.meta.dir);
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -21,10 +21,12 @@ describe("github-upload-public-key", async () => {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  it("creates new key if one does not exist", async () => {
 | 
					 | 
					 | 
					 | 
					  it("creates new key if one does not exist", async () => {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    const { instance, id, server } = await setupContainer();
 | 
					 | 
					 | 
					 | 
					    const { instance, id, server } = await setupContainer();
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    await writeCoder(id, "echo foo");
 | 
					 | 
					 | 
					 | 
					    await writeCoder(id, "echo foo");
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    let exec = await execContainer(id, [
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    const url = server.url.toString().slice(0, -1);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    const exec = await execContainer(id, [
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      "env",
 | 
					 | 
					 | 
					 | 
					      "env",
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      "CODER_ACCESS_URL=" + server.url.toString().slice(0, -1),
 | 
					 | 
					 | 
					 | 
					      `CODER_ACCESS_URL=${url}`,
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      "GITHUB_API_URL=" + server.url.toString().slice(0, -1),
 | 
					 | 
					 | 
					 | 
					      `GITHUB_API_URL=${url}`,
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      "CODER_OWNER_SESSION_TOKEN=foo",
 | 
					 | 
					 | 
					 | 
					      "CODER_OWNER_SESSION_TOKEN=foo",
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      "CODER_EXTERNAL_AUTH_ID=github",
 | 
					 | 
					 | 
					 | 
					      "CODER_EXTERNAL_AUTH_ID=github",
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      "bash",
 | 
					 | 
					 | 
					 | 
					      "bash",
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -42,10 +44,12 @@ describe("github-upload-public-key", async () => {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    const { instance, id, server } = await setupContainer();
 | 
					 | 
					 | 
					 | 
					    const { instance, id, server } = await setupContainer();
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    // use keyword to make server return a existing key
 | 
					 | 
					 | 
					 | 
					    // use keyword to make server return a existing key
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    await writeCoder(id, "echo findkey");
 | 
					 | 
					 | 
					 | 
					    await writeCoder(id, "echo findkey");
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    let exec = await execContainer(id, [
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    const url = server.url.toString().slice(0, -1);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    const exec = await execContainer(id, [
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      "env",
 | 
					 | 
					 | 
					 | 
					      "env",
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      "CODER_ACCESS_URL=" + server.url.toString().slice(0, -1),
 | 
					 | 
					 | 
					 | 
					      `CODER_ACCESS_URL=${url}`,
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      "GITHUB_API_URL=" + server.url.toString().slice(0, -1),
 | 
					 | 
					 | 
					 | 
					      `GITHUB_API_URL=${url}`,
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      "CODER_OWNER_SESSION_TOKEN=foo",
 | 
					 | 
					 | 
					 | 
					      "CODER_OWNER_SESSION_TOKEN=foo",
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      "CODER_EXTERNAL_AUTH_ID=github",
 | 
					 | 
					 | 
					 | 
					      "CODER_EXTERNAL_AUTH_ID=github",
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      "bash",
 | 
					 | 
					 | 
					 | 
					      "bash",
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -95,7 +99,7 @@ const setupServer = async (): Promise<Server> => {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }
 | 
					 | 
					 | 
					 | 
					        }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        // case: key already exists
 | 
					 | 
					 | 
					 | 
					        // case: key already exists
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (req.headers.get("Authorization") == "Bearer findkey") {
 | 
					 | 
					 | 
					 | 
					        if (req.headers.get("Authorization") === "Bearer findkey") {
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					          return createJSONResponse([
 | 
					 | 
					 | 
					 | 
					          return createJSONResponse([
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            {
 | 
					 | 
					 | 
					 | 
					            {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					              key: "foo",
 | 
					 | 
					 | 
					 | 
					              key: "foo",
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
 
 |