File tree Expand file tree Collapse file tree
test/integration/ssh_server Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -261,6 +261,31 @@ Arguments:
261261 return err
262262 }
263263
264+ // Load all files found in /etc/opk/prividers.d
265+ providerPolicyDir := "/etc/opk/providers.d"
266+ providerPolicyPaths , err := os .ReadDir (providerPolicyDir )
267+
268+ if err != nil {
269+ log .Println ("Failed to list files in /etc/opk/providers.d/:" , err )
270+ return err
271+ }
272+
273+ for _ , providerPolicyPath := range providerPolicyPaths {
274+ if ! providerPolicyPath .IsDir () {
275+
276+ thisProviderPolicy , err := policy .NewProviderFileLoader ().
277+ LoadProviderPolicy (providerPolicyDir + "/" + providerPolicyPath .Name ())
278+
279+ if err != nil {
280+ log .Printf ("Failed to load providers from %s/%s:\n %s" ,
281+ providerPolicyDir , providerPolicyPath .Name (), err )
282+ return err
283+ }
284+
285+ providerPolicy .Append (* thisProviderPolicy )
286+ }
287+ }
288+
264289 printConfigProblems ()
265290 log .Println ("Providers loaded: " , providerPolicy .ToString ())
266291
Original file line number Diff line number Diff line change @@ -63,6 +63,10 @@ func (p *ProviderPolicy) AddRow(row ProvidersRow) {
6363 p .rows = append (p .rows , row )
6464}
6565
66+ func (p * ProviderPolicy ) Append (n ProviderPolicy ) {
67+ p .rows = append (p .rows , n .rows ... )
68+ }
69+
6670func (p * ProviderPolicy ) CreateVerifier () (* verifier.Verifier , error ) {
6771 pvs := []verifier.ProviderVerifier {}
6872 var expirationPolicy verifier.ExpirationPolicy
Original file line number Diff line number Diff line change @@ -175,3 +175,35 @@ func TestProvidersFileLoader_ToTable(t *testing.T) {
175175 t .Error ("second row in table does not match expected values" )
176176 }
177177}
178+
179+ // Test ProvidersFileLoader.Append.
180+ func TestProvidersFileLoader_Append (t * testing.T ) {
181+ policy1 := ProviderPolicy {}
182+ policy1 .AddRow (ProvidersRow {
183+ Issuer : "issuer1" ,
184+ ClientID : "client1" ,
185+ ExpirationPolicy : "24h" ,
186+ })
187+ policy1 .AddRow (ProvidersRow {
188+ Issuer : "issuer2" ,
189+ ClientID : "client2" ,
190+ ExpirationPolicy : "48h" ,
191+ })
192+
193+ policy2 := ProviderPolicy {}
194+ policy1 .AddRow (ProvidersRow {
195+ Issuer : "issuer3" ,
196+ ClientID : "client3" ,
197+ ExpirationPolicy : "24h" ,
198+ })
199+ policy1 .AddRow (ProvidersRow {
200+ Issuer : "issuer4" ,
201+ ClientID : "client4" ,
202+ ExpirationPolicy : "48h" ,
203+ })
204+
205+ policy1 .Append (policy2 )
206+
207+ expected := "issuer1 client1 24h\n issuer2 client2 48h\n issuer3 client3 24h\n issuer4 client4 48h\n "
208+ require .Equal (t , expected , policy1 .ToString ())
209+ }
Original file line number Diff line number Diff line change @@ -66,7 +66,13 @@ RUN ls -l /usr/local/bin
6666RUN printenv PATH
6767
6868ARG ISSUER_PORT="9998"
69- RUN echo "http://oidc.local:${ISSUER_PORT}/ web oidc_refreshed" >> /etc/opk/providers
69+
70+ RUN mkdir -p /etc/opk/providers.d && \
71+ chown root:opksshuser /etc/opk/providers.d
72+
73+ RUN echo "http://oidc.local:${ISSUER_PORT}/ web oidc_refreshed" > /etc/opk/providers.d/oidc-local && \
74+ chown root:opksshuser /etc/opk/providers.d/oidc-local && \
75+ chmod 640 /etc/opk/providers.d/oidc-local
7076
7177# Add integration test user as allowed email in policy (this directly tests
7278# policy "add" command)
Original file line number Diff line number Diff line change @@ -61,7 +61,13 @@ RUN ls -l /usr/local/bin
6161RUN printenv PATH
6262
6363ARG ISSUER_PORT="9998"
64- RUN echo "http://oidc.local:${ISSUER_PORT}/ web oidc_refreshed" >> /etc/opk/providers
64+
65+ RUN mkdir -p /etc/opk/providers.d && \
66+ chown root:opksshuser /etc/opk/providers.d
67+
68+ RUN echo "http://oidc.local:${ISSUER_PORT}/ web oidc_refreshed" > /etc/opk/providers.d/oidc-local && \
69+ chown root:opksshuser /etc/opk/providers.d/oidc-local && \
70+ chmod 640 /etc/opk/providers.d/oidc-local
6571
6672# Add integration test user as allowed email in policy (this directly tests
6773# policy "add" command)
Original file line number Diff line number Diff line change @@ -46,7 +46,12 @@ RUN chmod +x ./scripts/install-linux.sh
4646RUN bash ./scripts/install-linux.sh --install-from=opksshbuild --no-sshd-restart
4747# RUN chmod 700 /usr/local/bin/opkssh
4848
49- RUN echo "http://oidc.local:${ISSUER_PORT}/ web oidc_refreshed" >> /etc/opk/providers
49+ RUN mkdir -p /etc/opk/providers.d && \
50+ chown root:opksshuser /etc/opk/providers.d
51+
52+ RUN echo "http://oidc.local:${ISSUER_PORT}/ web oidc_refreshed" > /etc/opk/providers.d/oidc-local && \
53+ chown root:opksshuser /etc/opk/providers.d/oidc-local && \
54+ chmod 640 /etc/opk/providers.d/oidc-local
5055
5156# Add integration test user as allowed email in policy (this directly tests
5257# policy "add" command)
You can’t perform that action at this time.
0 commit comments