o
    g                     @   s<  d dl mZ d dlZd dlmZmZmZmZ d dl	Z	d dl
Z
d dlmZ d dlmZ ejdejdee fddZejdejdefd	d
Zejdejdee fddZejdejdefddZejdejdeeeef  fddZejdejdeeef fddZg dZdee dee fddZejdejdefddZejdejdefddZejdejdee fddZejdejdeeeef  fddZdeeeef  deeef fd d!Zejdejdeeef fd"d#Zdeeef fd$d%Z ejdejdeeef fd&d'Z!d(edefd)d*Z"dS )+    N)AnyDictListOptional)TokenTransportHeader)collection_namedrawreturnc                 C   sd   t td d d d }| tjt ||d}t }g }|D ]}||v r%q|| || q|S )N
      min_sizemax_size)lenvalid_action_spacestlistsr   setaddappend)r   lengthnamesseenunseenname r   T/var/www/visachat/venv/lib/python3.10/site-packages/chromadb/test/auth/strategies.pymany_unique_names   s    
r   c                 C   s   | t jtjtj dddS )N   2   alphabetr   r   )r   textstringascii_lettersdigitsr   r   r   r   random_token$   s   r'   c                 C   s   | t tjtjd gS N)r   sampled_fromr   AUTHORIZATIONX_CHROMA_TOKENr&   r   r   r   random_token_transport_header+   s   r,   c                 C      | t jtjdddS Nr      r    r   r"   r#   r$   r&   r   r   r   random_user_name8      r1   c              
   C   s   | t jt t t jt ddddddd}g }t }t }|D ]}|d |v r- |S |d D ]}||v r9 nq1q"||d  |d D ]}|| qF|| |S )N   r
   r   )idtokensr   r4   r5   )r   r   fixed_dictionariesr1   r'   r   r   r   )r   usersunseen_users
seen_usersseen_tokensusertokenr   r   r   random_users_with_tokens=   s8   

r=   c                 C   s    | t  }td|i}||dS )Nr7   )r7   filename)r=   _dump_to_tmpfile)r   r7   r>   r   r   r   token_test_conf]   s   

r@   )zsystem:resetztenant:create_tenanttenant:get_tenantzdb:create_databasedb:get_databasezdb:list_collectionszdb:create_collectionzdb:get_or_create_collectioncollection:get_collectioncollection:delete_collectioncollection:update_collectioncollection:addcollection:deletecollection:getcollection:querycollection:peekcollection:countcollection:updatecollection:upsertauthorized_actionsc                    s    fddt D S )Nc                    s   g | ]}| vr|qS r   r   .0actionrN   r   r   
<listcomp>|   s    z(unauthorized_actions.<locals>.<listcomp>r   rR   r   rR   r   unauthorized_actions{   s   rU   c                 C   r-   r.   r0   r&   r   r   r   random_role_name   r2   rV   c                 C   s   | t tS r(   )r   r)   r   r&   r   r   r   random_action   s   rW   c                    sd   | t jt ddd t fdddD r d d v r$ d	  d
  d t S )Nr   r
   r   c                 3   s    | ]}| v V  qd S r(   r   rO   actionsr   r   	<genexpr>   s
    
z2random_allowed_actions_for_role.<locals>.<genexpr>)
rF   rG   rH   rI   rJ   rL   rM   rK   rE   rD   rC   rJ   rH   rA   rB   )r   setsrW   anyr   listr&   r   rX   r   random_allowed_actions_for_role   s   



r^   c                 C   sb   | t jt t t dddd}g }t }|D ]}|d |v r"q||d  || q|S )Nr4   rY   r   r
   r   r4   )r   r   r6   rV   r^   r   r   r   )r   rolesunseen_rolesr   roler   r   r   random_roles   s"   	rc   r`   c                 C   s,   i }| D ]}| |d d|d ii q|S )Nr4   rY   )update)r`   roles_mappingrb   r   r   r   _transform_roles_for_flush   s   rf   c                 C   sR   | t  }| t }|D ]}| tjdt|d d}|| d |d< q||dS )Nr   r   )	min_value	max_valuer4   rb   r7   r`   )r=   rc   r   integersr   )r   r7   r`   r;   
role_indexr   r   r   random_users_and_roles   s   


rl   c                   C   s   ddgddgdt dgdS )N__root__)r4   r5   rb   r_   ri   rT   r   r   r   r   _root_user_and_role   s   
rn   c                 C   sb   | t  }t }|d |d  |d |d  t|d t|d d}|d |d |dS )Nr7   r`   )r7   re   )r7   r`   r>   )rl   rn   extendr?   rf   )r   users_and_rolesroot_user_and_roler>   r   r   r   rbac_test_conf   s   

rr   datac                 C   sN   t jdd}t|jd}t| | W d    |jS 1 sw   Y  |jS )NF)deletew)tempfileNamedTemporaryFileopenr   yamldump)rs   tmpfr   r   r   r?      s   
r?   )#hypothesis.strategies
strategiesr   rv   typingr   r   r   r   ry   r#   chromadbr   !chromadb.test.property.strategiesr   	compositeDrawFnstrr   r'   r,   r1   r=   r@   r   rU   rV   rW   r^   rc   rf   rl   rn   rr   r?   r   r   r   r   <module>   sH    ""&	