我应该使用哪些Firebase安全规则来阅读邮件?

时间:2016-11-17 18:21:28

标签: firebase firebase-realtime-database firebase-security

我只希望这些用户阅读其uid等于to的{​​{1}}或from字段中的一个或两个的消息,或者如果'到'消息的部分设置为message
这是我的数据库:

all

我尝试了几条规则,并阅读了Firebase文档。但是这些规则都没有帮助我实现我的成果。

我尝试的规则的一个例子是:

{
"intents" : {
  "intentFields" : "",
  "intentName" : "",
  "to" : ""
},
"messages" : {
  "-KViVgc7ZG051eMXP0-5" : {
    "from" : "Ed",
    "name" : "Ed",
    "photoUrl" : "https://cdn1.iconfinder.com/data/icons/user-pictures/100/male3-512.png",
    "text" : "Hello, I'm Ed",
    "timeStamp" : "1476880306",
    "to" : "all",
    "type" : "text"
  },
  "-KWmsuvm0uJIf01eHfyN" : {
    "from" : "Capyv3mxQsUUn2W1nPOgcJ0Ex9T2",
    "name" : "Aakash Bansal",
    "photoUrl" : "https://lh5.googleusercontent.com/-oQyA4HXVycc/AAAAAAAAAAI/AAAAAAAAHKo/Ov0A0p0LjiY/s96-c/photo.jpg",
    "text" : "ho",
    "timeStamp" : "1479396273",
    "to" : "Ed",
    "type" : "text"
  }
}
}

以下规则可以正常运行,虽然它们无法实现我想要的结果,但它们会在应用中显示所有消息。

{
"rules": {
  "intents" : {
    ".read" : "auth.uid === data.child('to').val()",
    ".write" : true
  },
  "messages" : {
    "$message": {
           ".read":  "auth.uid !== null",
           ".write": true
    }
  }
}
}


只是告诉我,我在Android应用中使用firebaseui来读取数据。如果我对firebase安全规则的理解有问题,请告诉我。&b; 编辑:即使以下一套规则也无效:

{
"rules": {
  "intents" : {
    ".read" : "auth.uid === data.child('to').val()",
    ".write" : true
  },
  "messages" : {
    ".read":  "auth.uid !== null",
    "$message": {
           ".write": true
    }
  }
}
}


我用来读取数据的android代码是:

{
"rules": {
  "intents" : {
    ".read" : "auth.uid === data.child('to').val()",
    ".write" : true
  },
  "messages": {
    "$message": {
      ".read" : true,
      ".write": true
    }
  }
}
}

1 个答案:

答案 0 :(得分:0)

describe 'Post#save' do
  it "calls Mailer::notify!" do
    mock = MiniTest::Mock.new
    mock.expect(:call, nil, ['bla'])

    Mailer.stub(:notify!, mock) do
      post.save
    end

    mock.verify
  end
end