@@ -5,11 +5,7 @@ import * as Effect from "effect/Effect";
55import * as FileSystem from "effect/FileSystem" ;
66import * as Path from "effect/Path" ;
77
8- import {
9- discoverSshHosts ,
10- parseKnownHostsHostnames ,
11- resolveSshConfigIncludePattern ,
12- } from "./config.ts" ;
8+ import { discoverSshHosts , resolveSshConfigIncludePattern } from "./config.ts" ;
139
1410function makeTempHomeDir ( ) {
1511 return Effect . gen ( function * ( ) {
@@ -132,32 +128,42 @@ describe("ssh config", () => {
132128 ) ;
133129
134130 it . effect ( "parses known_hosts entries without returning hashed hosts" , ( ) =>
135- Effect . sync ( ( ) => {
131+ Effect . gen ( function * ( ) {
132+ const fs = yield * FileSystem . FileSystem ;
133+ const path = yield * Path . Path ;
134+ const homeDir = yield * makeTempHomeDir ( ) ;
135+ const sshDir = path . join ( homeDir , ".ssh" ) ;
136+ yield * fs . makeDirectory ( sshDir ) ;
137+ yield * fs . writeFileString (
138+ path . join ( sshDir , "known_hosts" ) ,
139+ [
140+ "github.com ssh-ed25519 AAAA" ,
141+ "gitlab.com,gitlab-alias ssh-ed25519 BBBB" ,
142+ "|1|hashed|entry ssh-ed25519 CCCC" ,
143+ "@cert-authority authority.example.com,*.example.com ssh-ed25519 DDDD" ,
144+ "[ssh.example.com]:2200 ssh-ed25519 EEEE" ,
145+ "port.example.com:22 ssh-ed25519 HHHH" ,
146+ "::1 ssh-ed25519 FFFF" ,
147+ "2001:db8::1 ssh-ed25519 GGGG" ,
148+ "" ,
149+ ] . join ( "\n" ) ,
150+ ) ;
151+
152+ const hosts = yield * discoverSshHosts ( { homeDir } ) ;
136153 assert . deepEqual (
137- parseKnownHostsHostnames (
138- [
139- "github.com ssh-ed25519 AAAA" ,
140- "gitlab.com,gitlab-alias ssh-ed25519 BBBB" ,
141- "|1|hashed|entry ssh-ed25519 CCCC" ,
142- "@cert-authority *.example.com ssh-ed25519 DDDD" ,
143- "[ssh.example.com]:2200 ssh-ed25519 EEEE" ,
144- "port.example.com:22 ssh-ed25519 HHHH" ,
145- "::1 ssh-ed25519 FFFF" ,
146- "2001:db8::1 ssh-ed25519 GGGG" ,
147- "" ,
148- ] . join ( "\n" ) ,
149- ) ,
154+ hosts . map ( ( { alias } ) => alias ) ,
150155 [
151156 "::1" ,
152157 "2001:db8::1" ,
158+ "authority.example.com" ,
153159 "github.com" ,
154160 "gitlab-alias" ,
155161 "gitlab.com" ,
156- "port.example.com" ,
157- "ssh.example.com" ,
162+ "ssh:// port.example.com:22 " ,
163+ "ssh://ssh .example.com:2200 " ,
158164 ] ,
159165 ) ;
160- } ) ,
166+ } ) . pipe ( Effect . provide ( NodeServices . layer ) , Effect . scoped ) ,
161167 ) ;
162168
163169 it . effect ( "expands tilde-prefixed ssh config include patterns" , ( ) =>
0 commit comments