
    b:                     8   d dl Z d dlZd dlmZ d dlmZ ej                            e          Zej        	                    ed          Z
ej        	                    ed          Zg dZd  ee          D             Z G d d	e          Z G d
 de          ZdS )    N)TestCaseInTempDir)pprintz../../../../bin/test_s4_loggingz../../../../bin/test_s3_logging)&alltdbprintdriverslanmansmb	rpc_parserpc_srvrpc_clipassdbsamauthwinbindvfsidmapquotaaclslockingmsdfsdmapiregistry	scavengerdnsldbtevent
auth_auditauth_json_auditkerberosdrs_replsmb2smb2_credits
dsdb_auditdsdb_json_auditdsdb_password_auditdsdb_password_json_auditdsdb_transaction_auditdsdb_transaction_json_auditdsdb_group_auditdsdb_group_json_auditc                     i | ]\  }}||	S  r,   ).0iks      6/usr/lib/python3/dist-packages/samba/tests/logfiles.py
<dictcomp>r1   '   s    6661q!666    c                       e Zd ZeZ	 	 	 ddZddZ	 	 ddZd Z	 dd	Z	d
 Z
d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS ) S4LoggingTests   defaultr,   c                 D   t           j                            | j        d          | _        t          | j        d          5 }|                    d           |>t           j                            | j        |          }|                    d| d           |                    d           |r|                    |            |D ]\  }}}|                    d           |                    |           ||                    d|            |=t           j                            | j        |          }|                    d	|            |                    d           d d d            n# 1 swxY w Y   |                     t           j        | j                   d S )
Nzsmb.confwz	[global]
z    log file = 
    log level =  :@)	ospathjointempdirsmbconfopenwrite
addCleanupunlink)	selfdefault_leveldefault_filemappingfdest	dbg_class	log_levellog_files	            r0   _write_smb_confzS4LoggingTests._write_smb_conf,   s    w||DL*==$,$$ 	GGL!!!'w||DL$02 22$222333GG&''' ,=*+++29 	( 	(.	9h	"""(GGO	OO,,,'7<<(02 2D GGJJJ'''GGDMMM+	 	 	 	 	 	 	 	 	 	 	 	 	 	 	, 		4<00000s    D$E00E47E4c                    | j         dz   }t          | j                   5 }t          |d          5 }|D ]e}d|v rJ|                    dd          d                                         }||                    d| d           P|                    |           f	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        || j                    |S )Nnewr8   z	log level=   r:   r9   )rB   rC   splitstriprD   r>   replace)rG   	new_levelsmbconf2rK   f2line	debug_args          r0   _extract_log_level_linez&S4LoggingTests._extract_log_level_lineJ   si    <%'$, 	'1h$$ ' ' 'D"d**$(JJsA$6$6q$9$?$?$A$A	$0HH%E	%E%E%EFFF'' ' ' ' ' ' ' ' ' ' ' ' ' ' '	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	
8T\***s5   B=A)B&B=&B*	*B=-B*	.B==CCNc                 f   t           j                            | j        |          }|g i}|D ]\  }}}	|	|}	t           j                            | j        |	          }
|                    |
g            ||k     rL|d |	fvrSd| dt
          |          d| }||
                             |           |S )N  logging for 'z' [z], at level )r>   r?   r@   rA   
setdefaultCLASS_CODESappend)rG   rJ   level_filterrI   file_filterr6   expectedrM   rN   rO   rK   ss               r0   _get_expected_stringsz$S4LoggingTests._get_expected_strings[   s     ',,t|\::R= /6 	" 	"*Iy('T\844A2&&&<''4"222,9 , ,Y1G , ,), ,AQKq!!!!r2   c           	      r   | j         d| j        dt          |          g|}t          j        |t          j        t          j                  }|                     |j        ddd                    |           d|j         d           |j	        
                                |j        
                                fS )	Nz-sz-L)stdoutstderrr   'r;   z
' failed ())serverrB   str
subprocessrunPIPEassertEqual
returncoder@   ri   decoderj   )rG   rN   
extra_argscmdps        r0   _run_s4_loggerzS4LoggingTests._run_s4_loggers   s    {T\S^^ 
 N3",/",/3 3 3 	qESXXc]]EEalEEE	G 	G 	G x  !(//"3"333r2   c                 \   t          |          }t          |                    d                    }||z  }||k    ro|rt          |           t          dt          |          t          |          fz             t          d           t	          ||z
             t          d          d S )Nr9   zexpected %d lines, found %dzmissing lines:zmissing lines)setrU   printlenr   AssertionError)rG   stringexpected_linesfilenamestring_linespresent_liness         r0   assert_string_containsz%S4LoggingTests.assert_string_contains   s    ^,,6<<--..$~5N**  h/~&&M(:(:;< = = ="###>M1222 111 +*r2   c                     t          |          5 }|                                }d d d            n# 1 swxY w Y   |                     |||           d S N)rC   readr   )rG   r   r   rK   r~   s        r0   assert_file_containsz#S4LoggingTests.assert_file_contains   s    (^^ 	qVVXXF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	##FNHEEEEE   155c                 f    |                     d          }||k    rt          d| d|           d S )Nzlogging for 'zstring has  lines, expected )countr}   )rG   r~   nr   s       r0   assert_n_known_lines_stringz*S4LoggingTests.assert_n_known_lines_string   sH    _--A:: 9e99a99; ; ; :r2   c                     t          |          5 }|                                }d d d            n# 1 swxY w Y   |                    d          }||k    rt          | d| d|           d S )Nr_   z has r   )rC   r   r   r}   )rG   r   r   rK   r~   r   s         r0   assert_n_known_linesz#S4LoggingTests.assert_n_known_lines   s    (^^ 	qVVXXF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	.//A:: ==%==!==? ? ? :r   c                 B   |                                 D ]\  }}t          j                            |          s|                     | d           |                     ||           |                     |t          |                     t          j        |           d S )Nz does not exist)	itemsr>   r?   existsfailr   r   r|   rF   )rG   expected_stringsr/   vs       r0   assert_unlink_expected_stringsz-S4LoggingTests.assert_unlink_expected_strings   s    $**,, 	 	DAq7>>!$$ 1		Q///000%%a+++%%aQ000IaLLLL	 	r2   c                     dfdt           D             }|                     |          }|                     |           |                               \  }}|                     |           d S )N   c                     g | ]}||fS r,   r,   r-   xlevels     r0   
<listcomp>z7S4LoggingTests.test_each_to_its_own.<locals>.<listcomp>   s    555QAua=555r2   rJ   
CLASS_LISTrg   rP   rx   r   rG   rJ   r   ri   rj   r   s        @r0   test_each_to_its_ownz#S4LoggingTests.test_each_to_its_own   s    5555*55555guEEW---,,U33++,<=====r2   c                     ddfdt           D             }|                     |          }|                     |           |                               \  }}|                     |           d S )Nr   
everythingc                     g | ]}|fS r,   r,   )r-   r   rL   r   s     r0   r   z2S4LoggingTests.test_all_to_one.<locals>.<listcomp>   s     888Aud#888r2   r   r   )rG   rJ   r   ri   rj   rL   r   s        @@r0   test_all_to_onezS4LoggingTests.test_all_to_one   s    88888Z88855guEEW---,,U33++,<=====r2   c                 
   dddgfdt          t                    D             }|                     |          }|                     |           |                               \  }}|                     |           d S )Nr   evenoddc                 8    g | ]\  }}|d z   |d z           fS rT   r,   r-   r.   r   destsr   s      r0   r   z1S4LoggingTests.test_bifurcate.<locals>.<listcomp>   @     6 6 6q! uqy%A,/ 6 6 6r2   r   	enumerater   rg   rP   rx   r   rG   rJ   r   ri   rj   r   r   s        @@r0   test_bifurcatezS4LoggingTests.test_bifurcate   s    6 6 6 6 6(446 6 655guEEW---,,U33++,<=====r2   c                 
   dddgfdt          t                    D             }|                     |          }|                     |           |                               \  }}|                     |           d S )Nr   r   r   c                 8    g | ]\  }}|d z
  |d z           fS r   r,   r   s      r0   r   zDS4LoggingTests.test_bifurcate_level_out_of_range.<locals>.<listcomp>   r   r2   r   r   r   s        @@r0   !test_bifurcate_level_out_of_rangez0S4LoggingTests.test_bifurcate_level_out_of_range   s     6 6 6 6 6(446 6 655guEEW---,,U33++,<=====r2   c                 X   d}d dg}g }t          t                    D ]3\  }}|dz  }|dz   |dz  z
  }|                    ||||         f           4|                     ||          }|                     |           |                     |          \  }	}
|                     |           d S )Nr   r   rT      r   )r   r   rb   rg   rP   rx   r   )rG   r   r   rJ   r.   r   parityrN   r   ri   rj   s              r0   test_bifurcate_misc_log_levelz,S4LoggingTests.test_bifurcate_misc_log_level   s     uj)) 	: 	:DAqUF	QU+INNAy%-8999955guEEW---,,U33++,<=====r2   c                    d}g d}g }d}t          t                    D ]:\  }}|dz  }|dz  dz   }|dz  }|dz  }|                    ||||         f           ;|                     ||          }	|                     |	           |                     d
          }
|                     |d|
          \  }}|                     |	           d S )Nr   Nabc{   r      rT   
      r      -d)r   r   rb   rg   rP   r]   rx   r   )rG   r   r   rJ   seedr.   r   drN   r   r\   ri   rj   s                r0   !test_all_different_ways_cmdline_dz0S4LoggingTests.test_all_different_ways_cmdline_d   s    %%%j)) 	5 	5DAqqA"9q=Dr	IDLDNNAy%(3444455guEEW---0044	,,UD)DD++,<=====r2   c                 R   d}g d}g }d}t          t                    D ]:\  }}|dz  }|dz  dz   }|dz  }|dz  }|                    ||||         f           ;|                     ||          }	|                     |	           |                     d           }
|                     |d
|
d          \  }}g }|	                                D ]!}|                    d |D                        "| 	                    ||           | 
                    |t          |                     d S )Nr   r   i  r      rT   r   r   r   r   -ic                 6    g | ]}|                                 S r,   rV   r-   r   s     r0   r   zPS4LoggingTests.test_all_different_ways_cmdline_d_interactive.<locals>.<listcomp>       "8"8"817799"8"8"8r2   )r   r   rb   rg   rP   r]   rx   valuesextendr   r   r|   )rG   r   r   rJ   r   r.   r   r   rN   r   r\   ri   rj   r   r   s                  r0   -test_all_different_ways_cmdline_d_interactivez<S4LoggingTests.test_all_different_ways_cmdline_d_interactive  s\   %%%j)) 	5 	5DAqqA"9q=Dr	IDLDNNAy%(3444455guEEW---0066	,,UD)TJJ!((** 	: 	:A!!"8"8a"8"8"89999##FN;;;((^1D1DEEEEEr2   c                     d t           D             }|                     |d          }|                     d |D                        |                     d          \  }}|                     |           d S )Nc                 ,    g | ]}|d ddgd|v          fS )r   r6   beesr   r,   r   s     r0   r   z9S4LoggingTests.test_only_some_level_0.<locals>.<listcomp>#  s=     ( ( ( q9f-cQh78 ( ( (r2   r   c                 *    g | ]}|d          dk    |S r5   r   r,   r   s     r0   r   z9S4LoggingTests.test_only_some_level_0.<locals>.<listcomp>&  !    %K%K%KAAaDFNNaNNNr2   r   r   )rG   rJ   r   ri   rj   s        r0   test_only_some_level_0z%S4LoggingTests.test_only_some_level_0  s    ( (&( ( (55gqAA%K%K%K%K%KLLL,,Q//++,<=====r2   c                     dfdt           D             }|                     |          }|                     d |D                        |                               \  }}|                     |           d S )Nr   c                 "    g | ]}d |v |dfS )r   r   r,   r   s     r0   r   z9S4LoggingTests.test_only_some_level_3.<locals>.<listcomp>.  s%    FFF!SAXXAuf%XXXr2   c                 *    g | ]}|d          dk    |S r   r,   r   s     r0   r   z9S4LoggingTests.test_only_some_level_3.<locals>.<listcomp>0  r   r2   r   r   r   s        @r0   test_only_some_level_3z%S4LoggingTests.test_only_some_level_3*  s     FFFFzFFF55guEE%K%K%K%K%KLLL,,U33++,<=====r2   c                     d}g }|                      ||          }|                     |           |                     |          \  }}|                     |           d S )Nr   r   )rg   rP   rx   r   rG   r   rJ   r   ri   rj   s         r0   	test_nonezS4LoggingTests.test_none4  sk    55guEEW---,,U33++,<=====r2   c                     d}d t           D             }|                     ||          }|                     g d           |                     |          \  }}|                     |           d S )Nr   c                     g | ]}|d dfS    r6   r,   r   s     r0   r   z9S4LoggingTests.test_none_high_default.<locals>.<listcomp>A      999Aq)$999r2   r   rJ   rH   r   r   s         r0   test_none_high_defaultz%S4LoggingTests.test_none_high_default<  s}     99j99955guEERq999,,U33++,<=====r2   c                     d}d t           D             }|                     ||          }|                     g            |                     |dd          \  }}|                     |           d S )Nr   c                     g | ]}|d dfS )r   r6   r,   r   s     r0   r   z;S4LoggingTests.test_none_high_cmdline_d.<locals>.<listcomp>K  s    :::!Ar9%:::r2   r   r   10r   r   s         r0   test_none_high_cmdline_dz'S4LoggingTests.test_none_high_cmdline_dH  s}    ::z:::55guEER(((,,UD$??++,<=====r2   c                 T   d}d t           D             }|                     ||          }|                     g d           |                     |d          \  }}g }|                                D ]!}|                    d |D                        "|                     ||           d S )Nr   c                     g | ]}|d dfS r   r,   r   s     r0   r   zGS4LoggingTests.test_interactive_high_default_simple.<locals>.<listcomp>U  r   r2   r   r   r   c                 6    g | ]}|                                 S r,   r   r   s     r0   r   zGS4LoggingTests.test_interactive_high_default_simple.<locals>.<listcomp>\  r   r2   )r   rg   rP   rx   r   r   r   )rG   r   rJ   r   ri   rj   r   r   s           r0   $test_interactive_high_default_simplez3S4LoggingTests.test_interactive_high_default_simpleR  s    99j99955guEERq999,,UD99!((** 	: 	:A!!"8"8a"8"8"89999##FN;;;;;r2   c                    d}d dg}g }t          t                    D ]3\  }}|dz  }|dz   |dz  z
  }|                    ||||         f           4|                     ||          }|                     |           |                     |d          \  }	}
g }|                                D ]!}|                    d |D                        "|                     |
|           d S )Nr   r   rT   r   r   r   c                 6    g | ]}|                                 S r,   r   r   s     r0   r   zDS4LoggingTests.test_interactive_complex_smb_conf.<locals>.<listcomp>t  r   r2   )	r   r   rb   rg   rP   rx   r   r   r   )rG   r   r   rJ   r.   r   r   rN   r   ri   rj   r   r   s                r0   !test_interactive_complex_smb_confz0S4LoggingTests.test_interactive_complex_smb_conf`  s   
 uj)) 	: 	:DAqUF	QU+INNAy%-8999955guEEW---,,UD99!((** 	: 	:A!!"8"8a"8"8"89999##FN;;;;;r2   )r5   r6   r,   )r5   )r6   Nr   )__name__
__module____qualname__	S4_SERVERrm   rP   r]   rg   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r,   r2   r0   r4   r4   *   s       F&'%. "1 1 1 1<   & ,5*.   04 4 4 )-2 2 2 2F F F
; ; ;? ? ?  > > >> > >	> 	> 	>> > >> > >:> > >(F F F2	> 	> 	>> > >> > >
> 
> 
>> > >< < << < < < <r2   r4   c                       e Zd ZeZdS )S3LoggingTestsN)r   r   r   	S3_SERVERrm   r,   r2   r0   r   r   y  s        FFFr2   r   )ro   r>   samba.testsr   r   r?   dirname__file__HEREr@   r   r   r   r   ra   r4   r   r,   r2   r0   <module>r      s  &     				 ) ) ) ) ) )      	wx  GLL@AA	GLL@AA	; ; ;
 76		* 5 5666L< L< L< L< L<& L< L< L<^
    ^     r2   